IPTC metadata extraction

This recipe allows the extract and display of IPTC metadata from your JPEG pictures. Note that not all pictures contain IPTC data, and not all PHP installations can extract it.

This recipe was suggested and tested by PmWiki user ~Kory at Cookbook:ThumbList-Talk-archive.

Thumblist version 20090416 or newer is required.

  1. Get the IPTC.php script from pear.php.net. Copy it to your /pmwiki/cookbook/ directory.
    • Note, recent PHP versions require an updated IPTC class which you can get from here: IPTC.txt. Rename it to IPTC.php and place it in the pmwiki/cookbook directory.
  2. Add to local/config.php :
$ThumbList['fEXIF'] = 'uThumbMetaData';
function uThumbMetaData($filepath)
{
  # get core Thumblist EXIF
  $vars = ThumbExif($filepath);
  # get IPTC tags
  $img = new Image_IPTC($filepath);
  $vars = array_merge($vars, array(
    '?x_headline' => $img->getTag('Headline'),
    '?x_caption' => $img->getTag('Caption'),
    '?x_copyright' => $img->getTag('Copyright String')
  ));
  return $vars;
}
include_once("$FarmD/cookbook/IPTC.php");

That's all. You can now use new question-variables ?x_headline, ?x_caption and ?x_copyright to display the corresponding IPTC entries. You can also display them in an ImageTemplate, via the new variables {*$ThumbList_x_headline}, {*$ThumbList_x_caption}, and {*$ThumbList_x_copyright}.

It is recommended to have all custom $ThumbList[] definitions in config.php before including the script (unless there is no way around, such as in a group customization).

In the same way you could define other custom question-variables. Note that there is a convention to use the ?x prefix for such extended variables.