#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    120
    Rep Power
    11

    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.

    Ex:
    Code:
       <img src="resize.py?img=blah.jpg&w=20&h=20">
    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.
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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 .

    http://www.devshed.com/c/a/Python/Imagine-Python/

    Have fun,

    Mark.
    Last edited by netytan; October 3rd, 2004 at 10:43 AM.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    120
    Rep Power
    11
    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.

IMN logo majestic logo threadwatch logo seochat tools logo