Actually, while I am thinking about it - make sure your script handles HTTP HEAD requests with a 304 if the content has not changed - that will tell the browser to use a cached version of the content instead of asking for the new version.
http://diveintopython.org/http_web_services/http_features.html#d0e27689 I know this is on the receiving end, but it might help with building the server - if that is what you are doing: http://diveintopython.org/http_web_services/etags.html -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Christian M. Jensen Sent: Thursday, June 23, 2005 1:35 PM To: Chris Cogdon; Rob Ballou Cc: [email protected] Subject: Re: [Image-SIG] Opening and saving quality JPEG files Pre-calculating the content length and informing the browser is a good thing too. Search Google for "Content-Length" header info. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Chris Cogdon Sent: Thursday, June 23, 2005 1:09 PM To: Rob Ballou Cc: [email protected] Subject: Re: [Image-SIG] Opening and saving quality JPEG files On Jun 23, 2005, at 12:54, Rob Ballou wrote: > Hello, > > I'm new to using PIL and I have what I hope is a quick question. > > I have created a script for displaying images to a web browser and I > have noticed that the quality PIL saves JPEGs isn't entirely what I'm > after. When displaying thumbnails (the main use of the script), the > quality is great. But when displaying a full size image without > modification, I noticed that there is some new JPEG compression taking > place (there are pronounced JPEG compression artifacts). > > The code that I have is: > > > im = Image.open(file) > print "Content-type: image/%s\r\n" % im.format.lower() > out= cStringIO.StringIO() > im.save(out, format, quailty=100, optimize=1) > out.reset() > print out.read() > out.close() > > > Changing quality and the optimized attributes have little to no effect > on the visual appearance of the image. I've tried to read the file > directly in binary mode and print that back to the browser, but it can > not display the image. > > I'm not really sure if I am going about these changes in the best > manner. Thanks in advance for any help. If you're not interested in processing the image, then there's no reason to run it through PIL Try this: im = Image.open(file) print "Content-type: image/%s\n" % im.format.lower() sys.stdout.write ( open(file).read() ) Ie... open it once so that PIL can get the format, then open it again to send through the web server. I'm using 'write' to avoid the extra newline at the end of the data (which is a bad thing to do). I'm also sending only a \n... the web server will automatically turn all newlines (\n) into NVT-ASCII newlines (\r\n). You don't want an extra \r in there. -- ("`-/")_.-'"``-._ Chris Cogdon <[EMAIL PROTECTED]> . . `; -._ )-;-,_`) (v_,)' _ )`-.\ ``-' _.- _..-_/ / ((.' ((,.-' ((,/ fL _______________________________________________ Image-SIG maillist - [email protected] http://mail.python.org/mailman/listinfo/image-sig _______________________________________________ Image-SIG maillist - [email protected] http://mail.python.org/mailman/listinfo/image-sig _______________________________________________ Image-SIG maillist - [email protected] http://mail.python.org/mailman/listinfo/image-sig
