Skip to content

Instantly share code, notes, and snippets.

@ankona
Last active August 29, 2015 14:22
Show Gist options
  • Save ankona/9669e608e72e69ac64db to your computer and use it in GitHub Desktop.
Save ankona/9669e608e72e69ac64db to your computer and use it in GitHub Desktop.
using a PIL.Image to write out to the response stream
from StringIO import StringIO
from google.appengine.api import images
out_stream = StringIO()
# put the data into a StringIO instance so we can manipulate it with PIL.Image
original_image_data = StringIO(source_img_response.read())
editable_image = Image.open(original_image_data)
editable_image.thumbnail((width, height), Image.ANTIALIAS)
editable_image.save(out_stream, "PNG")
# write the thumbnail stream directly out to the response instead of making another
# request back to <thumbnail_deck_url>/data/Thumbnail/SlideX.resize.HxW.png
writable_bytes = out_stream.getvalue()
self.response.out.write(writable_bytes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment