How to read IPTC keywords using PerlMagick?

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
kbro
Posts: 6
Joined: 2011-05-31T13:01:17-07:00
Authentication code: 8675308

How to read IPTC keywords using PerlMagick?

Post 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
kbro
Posts: 6
Joined: 2011-05-31T13:01:17-07:00
Authentication code: 8675308

Re: How to read IPTC keywords using PerlMagick?

Post 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"?
Post Reply