Getting instance numbers on tag names when only one instance returned

Started by dd-b, October 26, 2020, 02:40:14 PM

Previous topic - Next topic

dd-b

Reading metadata with a test script (and the utility I'm working on, but the test script is much simpler), I request 'IPTC:City', and get back from ImageInfo() "City (1)".  (From a particular image file, obviously; that file is attached)

This then breaks the rest of the script, where I try to count how many images have the "City" tag in them and how many different values for it there are in the set of files given to the utility (the test script does none of that, it's only fetching the data).

In that particular image file, there are in fact two "City" tags, one in IPTC and one in XMP. But I specifically request 'IPTC:City'; and it only returns one City tag. Is it proper for the instance number to be appended in parens like that?

The behavior doesn't change with different option values on the ImageInfo() call, as it turns out.

Also, as a side issue, but I noticed it while testing things around this issue, the command exiftool -city tparen.jpg returns only one instance of 'City'.  (exiftool -v tparen.jpg returns both, in amongst everything else).

I can fix the problem in my utility by removing any trailing '(<digits>)' in the tag names returned, of course. But clearly I don't yet understand how it's supposed to work, and maybe there's a better solution?

Here's the test script, and the image file is attached.


#!/usr/bin/env perl

# why are we getting city (1) back? in metastatus onl

use strict;
use warnings;
use v5.10;

use Image::ExifTool;
use Data::Dumper;

use constant CHECKTAGS => [
    qw (
   IPTC:City
   IPTC:SupplementalCategories
   IPTC:Keywords
   IPTC:by-line
   IPTC:copyrightnotice
   IPTC:specialinstructions
   ) ];


my $et = new Image::ExifTool;
my $f = 'tparen.jpg';
say "f is '$f'";
my $info = $et->ImageInfo ($f, CHECKTAGS, {
    # Options
    'Duplicates' => 1, #  return duplicate tags?
    'ListJoin' => undef, #  join multiple values?
    'PrintConv' => 0, #  convert to print format?
});
say "Info in '$f' is:\n", Dumper($info);


Phil Harvey

The keys in the hash returned by ImageInfo() are not tag names, they are what I call tag keys.  To get the tag name, do this:

    my $tagName = Image::ExifTool::GetTagName($tagKey)

On the command line, you must use the -a option to allow duplicate tags to be extracted.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

dd-b

And ImageInfo() docs actually say "Reference to hash of tag key/value pairs".  I read that as "key/value pairs" describing tags, but clearly you meant pairs of (tag key, value)!

Another level of call, another loop, to get the actual tag names, I guess.

Phil Harvey

Quote from: dd-b on October 26, 2020, 04:06:03 PM
And ImageInfo() docs actually say "Reference to hash of tag key/value pairs".  I read that as "key/value pairs" describing tags, but clearly you meant pairs of (tag key, value)!

Maybe it should say "tag-key/value pairs".  Would that be more clear?

Although, further down it explains more:

Return Value:

ImageInfo returns a reference to a hash of tag key/value pairs. The tag keys are identifiers -- essentially case-sensitive tag names with an appended instance number if multiple tags with the same name were extracted from the image.


- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

dd-b

True! And I remember seeing that before, but didn't find it lately. But I remembered enough to associate the '(1)' with instance identifiers, at least.

(It looked really weird at first; I was adding a '(<digit>)' myself to indicate how many tag values there were.)