Page 1 of 1

How to read IPTC keywords using PerlMagick?

Posted: 2011-06-04T05:03:52-07:00
by kbro
I have a set of images in a folder, and

Code: Select all

identify -format "%f %[IPTC:2:25]" *.jpg
shows me the tags that I put into them using Picasa. I now want to extract the tags in a Perl program. I know I could use Image::IPTC, but I don't want to double-handle the file. I was hoping I could use

Code: Select all

$image->Get(xxx)
but the somewhat sparse documentation on the PerlMagick page doesn't say anything about IPTC (or EXIF, for that matter!) Is there a way?

thanks
Kevin

Re: How to read IPTC keywords using PerlMagick?

Posted: 2011-06-04T05:21:40-07:00
by kbro
This seems to work:

Code: Select all

use Image::Magick;

foreach my $file (<@ARGV>)
{
    my $image = new Image::Magick;

    $image->Read($file);

    my @keywords = split ';', $image->Get('IPTC:2:25');

    print "$file: @keywords\n";
}
The split() is needed because multiple keywords are separated by semicolons (same as identify).

Hmm... Is there a way to use "Keyword" rather than "2:25"?