IPTC Info Extractor
By Josh Carter IntroductionEver wish you add information to your photos like a caption, the place you took it, the date, and perhaps even keywords and categories? You already can. The International Press Telecommunications Council (IPTC) defines a format for exchanging meta-information in news content, and that includes photographs. You can embed all kinds of information in your images. The trick is putting it to use. That's where this IPTCInfo Perl module comes into play. You can embed information using many programs, including Adobe Photoshop, and IPTCInfo will let your web server -- and other automated server programs -- pull it back out. You can use the information directly in Perl programs, export it to XML, or even export SQL statements ready to be fed into a database. Download itCurrent version is 1.5. The module should now work correctly on Intel architectures, and it has a proper makefile for easy installation. Double-bonus in 1.5 is that you can save IPTC info in JPEG files! This tool requires Perl 5. It doesn't need anything other than a stock installation, and should work equally well on all platforms. I've tested it under MkLinux and MacOS X. Email me with any bugs you may stumble across. Please also read the disclaimer in the docs about saving files.
Download IPTCInfo 1.5 (33 kb .tar.gz)
Why IPTC?Perhaps you think a database would be great for storing image information. In many ways, you're right, but the problem is this: as soon as you copy that image somewhere else, email it to someone, or otherwise disconnect the image from the database, all that information is lost. Wouldn't it be much better if the information could go with the image by being in the image? Many aspects of managing your images are made easier using IPTC's standard for embedding image metadata in the image itself. Many software programs already exist for doing this, including Adobe Photoshop. It's the standard used by professional news agencies worldwide, and it's just as useful for others, too. With this IPTCInfo module for Perl, it's a piece of cake to also keep a database of image information for fast searching: you can export the information as XML and/or SQL statements for feeding into your own database. Using IPTCInfoInstall the module as documented in the README file. You can try out the demo program called "demo.pl" which extracts info from the images in the "demo-images" directory. To integrate with your own code, simply do something like the following: use Image::IPTCInfo; # Create new info object my $info = new Image::IPTCInfo('file-name-here.jpg'); # Get list of keywords... my $keywordsRef = $info->Keywords(); # Get specific attributes... my $caption = $info->Attribute('caption/abstract'); # ...and so forth. Please read the docs using perldoc Image::IPTCInfo for more complete information. XML and SQL Export FeaturesIPTCInfo also allows you to easily generate XML and SQL from the image metadata. For XML, call: $xml = $info->ExportXML('entity-name', \%extra-data, 'optional output file name'); This returns XML containing all image metadata. Attribute names are translated into XML tags, making adjustments to spaces and slashes for compatibility. (Spaces become underbars, slashes become dashes.) You provide an entity name; all data will be contained within this entity. You can optionally provides a reference to a hash of extra data. This will get put into the XML, too. (Example: you may want to put info on the image's location into the XML.) Keys must be valid XML tag names. You can also provide a filename, and the XML will be dumped into there. See the "demo.pl" script for examples. For SQL, it goes like this: my %mappings = ( 'IPTC dataset name here' => 'your table column name here', 'caption/abstract' => 'caption', 'city' => 'city', 'province/state' => 'state); # etc etc etc. $statement = $info->ExportSQL('mytable', \%mappings, \%extra-data); This returns a SQL statement to insert into your given table name a set of values from the image. You pass in a reference to a hash which maps IPTC dataset names into column names for the database table. As with XML export, you can also provide extra information to be stuck into the SQL. IPTC Attribute Reference
|
All material copyright (c) 1999-2001 Josh Carter. All rights reserved.