[Tutor] identifying graphics attributes
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Mon, 25 Feb 2002 18:04:12 -0800 (PST)
On Mon, 25 Feb 2002, Erik Price wrote:
> inconvenient. It would be nice if there were a program that could do
> the work of identifying the file's information (basic attributes like
> width and height and resolution by crawling through a directory and
> extracting the relevant data from the file.
Hi Erik,
Yes, we can do this with the Python Imaging Library (PIL):
http://www.pythonware.com/products/pil/
PIL is well suited for image manipulations. If we use PIL, the problem is
not bad at all --- I think it would involve doing something like:
###
## Warning, warning, untested code
for file in files:
im = Image.open(file)
print "%s has dimensions %s and is of size %s bytes" % \
(file, im.size, os.path.getsize(file))
###
> of detail involved is not very great (the important parts are
> literally the width, height, file size, and filename), this doesn't
> seem like a completely unapproachable task.
I think this should be a great first Python script. *grin* By the way, if
you'd like more details on os.path, you can look at:
http://www.python.org/doc/lib/module-os.path.html
Another interesting module would be the 'glob' module:
http://www.python.org/doc/lib/module-glob.html
which helps us pull all the files in a given directory.
Hope this helps!