The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Image::IPTCInfo - Perl extension for extracting IPTC image meta-data

SYNOPSIS

  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.

DESCRIPTION

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.

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 what's in the synopsys above.

The complete list of possible attributes is given below. These are as specified in the IPTC IIM standard, version 4. Keywords and categories are handled differently: since these are lists, the module allows you to access them as Perl lists. Call Keywords() and Categories() to get a reference to each list.

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

KNOWN BUGS

IPTC meta-info on MacOS may be stored in the resource fork instead of the data fork. This program will currently not scan the resource fork.

Some programs will embed IPTC info at the end of the file instead of the beginning. The module will currently only look near the front of the file. You can change this behavior in ScanToFirstIMMTag if needed. Future versions should be smarter about scanning JPGs for this info.

IPTCInfo can't modify your images, i.e. adding or changing the info in them. Some day it will.

AUTHOR

Josh Carter, josh@multipart-mixed.com

SEE ALSO

perl(1).