[Tutor] identifying graphics attributes

Erik Price erikprice@mac.com
Mon, 25 Feb 2002 19:16:56 -0500

Hello, everyone:

I have been reading quite a bit about Python over the past month (since 
I first subscribed to this list), and experimenting with the interpreter 
when I have the opportunity.  I'm really impressed with this language, 
and if I wasn't already halfway through my work project (in PHP), I 
would see if I could do it using Python instead.

However, I have come upon a possible dilemma, and I am thinking that 
Python might be just the language to use for this.  Let me explain:

The project that I am working on is essentially a scaled-down content 
management system, to simply keep track of a database of project 
information and information about graphics files.  For instance, when 
someone in our design studio creates a new image, and burns it to a CD, 
they will at the same time go to the web site (my project) and enter 
some information about the file such as its height and width in inches, 
its size in MB, its resolution, and who they created it for.  There are 
other features of this application that aren't really relevant to the 
point of this post.

One of my co-workers brought up a very good point -- once in a while, a 
designer has a CD with sometimes 50 or more images on it, which will 
need to be added to the database.  This is kind of a problem, because 
while it's not a big deal to fill out the information for ten or fifteen 
files and submit them to the database via the web site, sitting there 
and filling out fifty or more HTML forms is going to be a bit 
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.

PHP is not a good language for doing this, since it's really intended 
for developing dynamic web sites, but it seemed that this is something 
that Python might be able to do.  The Python script could crawl through 
a directory of files, extract the relevant information about each of 
them and write them in XML to a file.  The file could then be sent to 
the web server, where another Python script would parse the information 
and form the relevant SQL statements to insert this data into the 
database.  Because the level 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.

Is there a resource I could look to for information about using Python 
to "examine" graphics files (like Photoshop or Illustrator documents)?  
This will need to run on Mac OS 9, though that can be worked around if 
necessary (I have Unix and windows machines at my disposal as well).  I 
would appreciate any input that anyone can give -- I know it seems like 
a pretty big project to tackle right off the bat, but I'm really 
interested in the plausibility of something like this.

Thanks very much