ExifTool Forum

ExifTool => The Image::ExifTool API => Topic started by: scottso on May 03, 2012, 08:56:42 AM

Title: output by groupHeading and/or groupName
Post by: scottso on May 03, 2012, 08:56:42 AM
The way exiftool application outputs info using its -g (groupHeadings) and -G (groupNames) options is very useful in grouping the tags, but I'm having a heck of a time generating similar output using the perl mod.  Could anyone point me in the right direction?  I'm putting the key, value in a Tk::TableMatrix::Spreadsheet, and would like to have better control of the output.

Scott
Title: Re: output by groupHeading and/or groupName
Post by: Phil Harvey on May 03, 2012, 09:12:17 AM
Hi Scott,

There are various ways to do this.  Personally, I would use the Sort option to sort by group, and return a sorted list of tag keys from ImageInfo(), then call GetGroup() on each tag to see what group it is, and print the group heading when the group changes.  Alternatively, there is sample code for another (slightly less efficient) method in the GetGroups() documentation (https://exiftool.org/ExifTool.html#GetGroups).

- Phil
Title: Re: output by groupHeading and/or groupName
Post by: scottso on May 21, 2012, 12:07:35 PM
I've finally had a little time to get back to this, and I'm still having trouble.  The GetGroups() sample code basically does what I want, but I was trying to go down your suggested route to sort the ImageInfo output.  Here's a snip of what I'm trying:


#!/bin/env perl -w

use Image::ExifTool;

my $exifTool = new Image::ExifTool;
$exifTool->Options(Sort => 'Group1', Sort2 => 'Tag');

my $info = $exifTool->ImageInfo(shift(@ARGV));

my $counter = 0;

foreach (keys %$info) {
$counter++;
my $val = $$info{$_};
if (ref $val eq 'ARRAY') {
$val = join(',', @$val);
} elsif (ref $val eq 'SCALAR') {
$val = '(Binary data)';
}

print "Key $counter:  Group:  " . $exifTool->GetGroup($_) . "  Tag:  $_ --> $val\n";
}

my $size = scalar(keys %$info);
print "\n$size\n";

exit;


It doesn't matter if I use Sort2 or not.  Sample output:


Key 208:  Group:  EXIF  Tag:  DateTimeOriginal (1) --> 2012:03:06 20:31:05
Key 209:  Group:  MakerNotes  Tag:  RawImageCenter --> 2336 1542
Key 210:  Group:  MakerNotes  Tag:  FlashMode --> Did Not Fire
Key 211:  Group:  EXIF  Tag:  Software --> Ver.1.01
Key 212:  Group:  Composite  Tag:  AutoFocus --> Off
Key 213:  Group:  MakerNotes  Tag:  NoiseReduction --> Off


I've the perl-Image-ExifTool-8.65-30.1.noarch rpm installed on openSuSE 12.1, from their repo.
Title: Re: output by groupHeading and/or groupName
Post by: Phil Harvey on May 21, 2012, 08:22:25 PM
Right.

In Perl, the keys of a hash have not particular order.

To return the ordered tag keys, pass an array reference to Image Info.  The ordered tag keys will be returned in this array, as in the examples.

- Phil