multipart-mixed

IPTCInfo Perl Module

Ever 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 it

Current version is 1.9. Has a couple bug fixes and some esoteric features over 1.7.

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, and heard positive reports from other platforms. Email me with any bugs you may stumble across.

Download IPTCInfo 1.9 (36 kb .tar.gz)
Download IPTCInfo 1.9 (40 kb .zip)

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 IPTCInfo

Install 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 Features

IPTCInfo 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

object name                  originating program
edit status                  program version
editorial update             object cycle
urgency                      by-line
subject reference            by-line title
category                     city
fixture identifier           sub-location
content location code        province/state
content location name        country/primary location code
release date                 country/primary location name
release time                 original transmission reference
expiration date              headline
expiration time              credit
special instructions         source
action advised               copyright notice
reference service            contact
reference date               caption/abstract
reference number             writer/editor
date created                 image type
time created                 image orientation
digital creation date        language identifier
digital creation time

Comments

Does this work with the pictures that picasa has added a "nonstandad_117" tag to? The python version of this file does not work, but this one is newer.

I haven't studied this in detail, but my understanding is that Picasa does not replace the IPTC info in a file, rather it tacks new info onto the end of a file. There is a semi-standard way of doing this (not documented in my books, unfortunately) and most programs appear to support this behavior.

IPTCInfo, however, only searches for the first IPTC block it finds, then modifies that. Thus changes you make via IPTCInfo on these images will appear to have no effect, because the Picasa data at the end will remain unchanged.

At the moment I don't have time to make the changes required to properly support Picasa. I'd love to find a new maintainer for IPTCInfo who could make these changes and more. Unfortunately I have been unsuccessful so far.

Hello,
I am using IPTCInfo and want to be able to read a value from the keywords field.
$keywordsRef = $info->Keywords();
but this returns ARRAY(0x1d989d0).

How do I get it to assign it as a string?

Thanks

Neill

P.S I am a perl newbie so apologies in advance if this is an eay answer

Keywords returns an array since a picture can have multiple keywords. You can loop over them using something like:

    foreach $keyword (@$keywordsRef)
    {
        print "  keyword : $keyword\n";
    }

Hi,

how can i load the infos in an hash instead of an array? is there any buildin for this?

Post a comment