ExifTool Forum

ExifTool => The Image::ExifTool API => Topic started by: quix on April 26, 2016, 04:38:06 AM

Title: Filtering IPTC metadata by Record
Post by: quix on April 26, 2016, 04:38:06 AM
I need to to read (not write) IPTC metadata, but only from the ApplicationRecord, not from any of the other Records/SubDirectorys such as IPTCEnvelope, IPTCNewsPhoto etc.

I haven't found a way to get ImageInfo() to do this:


my @group = qw / IPTC /;
my $exifTool = new Image::ExifTool;
$exifTool->Options(Group0 => \@group, Unknown => 1);
my $metadata = $exifTool->ImageInfo($myfile, 'iptc:*'); # wrong: selects all



So, to be able to filter items when looping through $metadata, I preprocess the IPTC tag tables by prefixing tag names in those tables I'm not interested in with a "!":


sub preprocessIPTCTables {

    my @tablenames;
    my $maintable = Image::ExifTool::GetTagTable('Image::ExifTool::IPTC::Main');

    # get names of all tag tables except 'IPTCApplication'
    for my $key (keys %{$maintable}){
        next unless($key =~ m/^\d+$/);
        next if($maintable->{$key}->{Name} eq 'IPTCApplication');
        push(@tablenames, $maintable->{$key}->{SubDirectory}->{TagTable});
    }

    # prefix Tag Names with "!"

    for my $name (@tablenames){
        my $table = Image::ExifTool::GetTagTable($name);

        # _all_ names, not just the known ones
        for (0..255){
            if(defined $table->{$_}){
                $table->{$_}->{Name} = "!" . $table->{$_}->{Name};
            }
            else{
                $$table{$_} = { Name => "!", Format => 'string[1]' };
            }
        }
    }
}


Although this has the desired effect, I wonder if there's a way to select the right table(s) without relying on the API not to change, preferably by setting the group argument of $exifTool->ImageInfo() correctly.

Any clues?
Title: Re: Filtering IPTC metadata by Record
Post by: Phil Harvey on May 02, 2016, 11:21:34 AM
Sorry for the delay in responding.

Currently there are not separate groups for the IPTC ApplicationRecord vs. other IPTC records.  The way to do get only ApplicationRecord tags is to make a list of all ApplicationRecord tags, and request only these when calling ImageInfo():

    $exifTool->ImageInfo($myfile, \@listOfAllApplicationRecordTags);

- Phil