October 2nd, 2004, 04:32 PM
Resize and return image on a website. How?
What I'd like to do is pass the path of an image off to my script, have it resize the image and return the resized image to be used within actual img tags.
The only problem I have right now is how to make it actually return an image using PIL.
I've seen this done with ASP and COM objects, but as Python is free, it would certainly seem to be a better alternative.
Any help or tips are very appreciated, thanks.
October 3rd, 2004, 11:39 AM
I don't know if you've found this yet. But there is an article on devshed on PIL, which might help. What you would need to do is:
1. load the image with PIL
2. resize it
3. and save the image with a slightly different name i.e. masterImage and resizedImage, then use the resizedImage in the webpage rather than it's original.
This is of course assuming that the image doesn't need to be dynamically generated, say for each user. In which case, or course, the process would be slightly different. But the basic idea is there .
Last edited by netytan; October 3rd, 2004 at 11:43 AM.
October 4th, 2004, 11:21 AM
After 5 hours of searching/testing I managed to get it to work by reading in the file to a StringIO object, resizing the image and storing it into another StringIO object and sending the output straight to the browser.
Thanks for your reply though. My only problem now is a way to map between the physical path and the url path, something equivalent to ASP's Server.MapPath() function.