Last active
August 29, 2015 14:22
-
-
Save ankona/9669e608e72e69ac64db to your computer and use it in GitHub Desktop.
using a PIL.Image to write out to the response stream
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
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