Skip to content

Instantly share code, notes, and snippets.

@danielatdattrixdotcom
Created October 3, 2012 23:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielatdattrixdotcom/3830519 to your computer and use it in GitHub Desktop.
Save danielatdattrixdotcom/3830519 to your computer and use it in GitHub Desktop.
Source Generator for Django app easy-thumbnails that uses Wand (ImageMagick)
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