[Image-SIG] Using PIL to display resized images over the web
Jay Dorsey
jay at jaydorsey.com
Wed Oct 15 22:30:40 EDT 2003
>> I have a simple photo website written in python. I would like to be
>>able to use Python Imaging Library to read an image file from the disk,
>>resize/thumbnail it in memory, and then print the modified image
>>(sending it to the client web browser after the proper MIME headings).
>
I missed the OP's message, but how about something like this:
from cStringIO import StringIO
import Image
import sys
tmp = StringIO()
img = Image.open("/path/to/my/image.jpg")
img.thumbnail(img, (100, 100))
img.save(tmp, "JPEG", quality=70)
tmp = tmp.getvalue(tmp.seek(0))
sys.stdout.write("HTTP/1.1 200 OK\nConnection: Close\nContent-type:
image/jpeg\nContent-length: %d\n\n%s" % (int(len(tmp)), tmp)
I used something similar to the above in a thumbnailing project I did a
while ago.
Jay
More information about the Image-SIG
mailing list