getting Caption value

Started by lfcnutter, October 05, 2022, 09:13:10 AM

Previous topic - Next topic

lfcnutter

I'm trying to sort out my collection which over time has various typo's and mis-spellings etc.
I've pretty much got everything sorted with one exception - namely XMP:Caption-Abstract.
I've used the example from MEDTA::CPAN to show me all tags and values from a test jpg which I know has the caption tag.
My Perl is very rusty and I cannot work out how to get the value of the returned Hash,
Can any one help with this syntax please?
Code:
#!/usr/bin/perl -w
#
#
use Image::ExifTool;
my $exifTool = new Image::ExifTool;
$exifTool->Options(Unknown => 1);
my $info = $exifTool->ImageInfo('G:/wamp64/www/TestPhotoTags/Photos/Other/camera03.JPG');

my $group = '';
my $tag;
foreach $tag ($exifTool->GetFoundTags('Group0'))
{
    if ($group ne $exifTool->GetGroup($tag))
        {
        $group = $exifTool->GetGroup($tag);
        print "---- $group ----\n";
    }
    my $val = $info->{$tag};
       
    if (ref $val eq 'SCALAR')
        {
        if ($$val =~ /^Binary data/)
                {
            $val = "($$val)";
        }
                else
                {
            my $len = length($$val);
            $val = "(Binary data $len bytes)";
        }
    }
    printf("%-32s : %s\n", $exifTool->GetDescription($tag), $val);
}

StarGeek Edit: Edited to correct formatting.  Please use the button for exiftool code/output.

StarGeek

Your code appears to work correctly here
C:\Programs\My_Stuff>test.pl
---- ExifTool ----
ExifTool Version Number          : 12.42
---- File ----
File Name                        : Test4.jpg
Directory                        : y:\!temp
File Size                        : 449 kB
File Modification Date/Time      : 2022:09:29 16:00:52-07:00
File Access Date/Time            : 2022:10:05 08:16:12-07:00
File Creation Date/Time          : 2022:09:29 12:00:00-07:00
File Permissions                : -rw-rw-rw-
File Type                        : JPEG
File Type Extension              : jpg
MIME Type                        : image/jpeg
Current IPTC Digest              : b766aa8110fc406204de90b7974957a7
Image Width                      : 1749
Image Height                    : 1205
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                  : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
---- IPTC ----
Headline                        : headline
Caption-Abstract                : Description
Application Record Version      : 4
---- XMP ----
XMP Toolkit                      : Image::ExifTool 12.47
Description                      : Description
Headline                        : headline
---- Composite ----
Image Size                      : 1749x1205
Megapixels                      : 2.1

Caption-Abstract is a IPTC IIM/Legacy tag, not XMP.  The equivalent XMP tag is Description.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

lfcnutter

Hi StarGeek,
thanks for reply.
I realised I was several versions of exiftool out of date so have just updated and rerun script.
I'm still getting Hash returned for Caption.
I have attached the output from script so could you please take another look and let me know?
PS: although I have updated, the XMP toolkit is showing as 10.20.
Could this be part of my problem?
many thanks

Phil Harvey

This will happen if Caption is a structure and you have enabled the Struct option.  Are you using a .ExifTool_config file that enables the API Struct option?  If not, post the original XMP (ie. out.xmp from the command below) and we should be able to figure it out.

exiftool -xmp -b G:/wamp64/www/TestPhotoTags/Photos/Other/IMG_0001.jpg > out.xmp

"Caption" is not a standard XMP tag, so I would need to see the XMP to know what is going on.

- 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 ($).

lfcnutter


lfcnutter

sorry hit escape by accident

So as far as I know I'm using standard config. I've never changed anything in this.

output from command is attached.

thanks for progressing this

StarGeek

Quote from: lfcnutter on October 06, 2022, 04:25:30 AMI'm still getting Hash returned for Caption.

From the attached file

<rdf:Description rdf:about=''
  xmlns:acdsee='http://ns.acdsee.com/iptc/1.0/'>
  <acdsee:caption>HASH(0x3dd9880)</acdsee:caption>
 </rdf:Description>

So you're getting HASH because that is the value that Caption has been set to.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

Quote from: StarGeek on October 06, 2022, 10:06:01 AM<acdsee:caption>HASH(0x3dd9880)</acdsee:caption>
So you're getting HASH because that is the value that Caption has been set to.

Wow.  I didn't see that one coming!  :P

Surely ExifTool wrote this XMP, so the question is: How did that value get in there?  It could happen if a structure was written incorrectly to a string-type tag via the API.  If it happens via the exiftool app, then it is something that needs to be fixed.

- 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 ($).

lfcnutter

Maybe I can shed some light here.
I used exiftool to write the tags to a csv file
as per
exiftool -csv -Caption-Abstract -Comment -Description -ImageDescription -Headline -ObjectName -Title -UserComment -Subject -Keywords "G:/wamp64/www/TestPhotoTags/Photos/*/*.jpg" > out.csv

I then modified the contents of the csv file to correct the typos and mistakes and reloaded
as per
exiftool -csv=out.csv "G:/wamp64/www/TestPhotoTags/Photos/*/*.jpg"

could this be a mistake on my part that's caused the problem?


Phil Harvey

That shouldn't write a "Caption" tag, unless you changed the heading from "Caption-Abstract" to "Caption", but even then it shouldn't write a structure like that.

- 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 ($).

lfcnutter

Ok so I have attached two csv files
the first as generated by the -csv command
and the second by the -csv= command

at present I haven't run the second command as I don't want to screw up any more.

Hope this helps

Phil Harvey

Neither CSV shows any entries containing the word "HASH", so this isn't where it came from.

- 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 ($).

StarGeek

The only time I've gotten a HASH value is when I'm writing code for a user defined tag and I don't properly de-reference something.  I can never keep straight what's a reference and what's not and how to properly de-reference a value.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

Yes, that can be confusing sometimes.

- 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 ($).

lfcnutter

OK guys,I think I'm sorted now.
I've abandoned the -csv -csv= approach in favour of a perl script.
I found that keywords and subject were being added as a single keyword using above method.

I have now got my perl script sorted and can now update all my tags as I wanted.
Sorry if I've taken up so much of your time and effort it's been really appreciated.

regards and thanks for a brilliant exifTool