I want to display web images as thumbnails! Reading and writing images from the file system is full of information, I wanted to cache it in memory and process it, so I tried it.
--I want to resize the image and create a thumbnail --I want to create a response without writing an image taken from the Web to a file (I want to cache it in memory) --I want to return an image response in Flask
url = 'http://www.google.co.jp/intl/ja_jp/images/logo.gif'
buffer = urllib2.urlopen(url).read()
img = Image.open(StringIO(buffer))
size = (120, 75)
img.thumbnail(size)
buf = StringIO()
img.save(buf, 'png')
response = helpers.make_response(buf.getvalue())
response.headers["Content-type"] = "Image"
return response
Code on Github
*reference http://effbot.org/imagingbook/pil-index.htm
Recommended Posts