Created
October 3, 2012 23:20
-
-
Save danielatdattrixdotcom/3830519 to your computer and use it in GitHub Desktop.
Source Generator for Django app easy-thumbnails that uses Wand (ImageMagick)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
from cStringIO import StringIO | |
except ImportError: | |
from StringIO import StringIO | |
from PIL import Image as PILImage | |
from wand.image import Image | |
# Source Generator for the easy-thumbnails Django application | |
# https://github.com/SmileyChris/easy-thumbnails | |
# | |
# This generator fills in some of the gaps left by using only PIL. | |
# It uses Wand ( https://github.com/dahlia/wand ), which is an | |
# ImageMagick binding for Python. Result: More file formats! | |
def wand_image(source, **options): | |
if not source: | |
return | |
try: | |
# Read source file, output PNG blob and finally off to PIL for return | |
raw = StringIO(Image(filename=str(source.file)).make_blob('png')) | |
raw.seek(0) | |
image = PILImage.open(raw) | |
except Exception: | |
return | |
return image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment