[Tutor] getImageInfo() ?

Roger Merchberger zmerch at 30below.com
Thu Oct 28 21:38:19 CEST 2004


Rumor has it that Olli Rajala may have mentioned these words:
>Hi!
>This is my first post to this list, so I thought to say hi. :)
>
>I'm doing my own imagegallery using python and thought if there were
>some good/easy way to find the info of the pic, I mean the
>width&height, so I could put them on the page in the <img>-tag. Pics
>are jpegs if that matters.

You'll need to install the PIL (Python Image Library), then try
this code snippet:

import Image

jpgfilename = 'c:/mypicture.jpg'  # for winders...
# jpgfilename = '/home/myhome/mypicture.jpg'   # uncomment for *nix

pix = Image.open(jpgfilename)
(xsize, ysize) = pix.size

# =-=-=-=-=-=-=-=-=-=-=-=-=-=

There are many functions in the PIL, including resizing the image and I 
believe even converting it from one format to another.

I have an application that changes my Winders background every 5 minutes, 
and I use the code above (with the Image.getpixel command) to extract a 
background pixel from each to re-set the background color of the desktop, 
so I don't have to stretch the image out of proportion...

(It also changes my Eudora .sig file, and my new mail alert .wav ;-) )

HTH,
Roger "Merch" Merchberger

--
Roger "Merch" Merchberger   | "Profile, don't speculate."
SysAdmin, Iceberg Computers |     Daniel J. Bernstein
zmerch at 30below.com          |



More information about the Tutor mailing list