ExifTool Forum

ExifTool => The Image::ExifTool API => Topic started by: RicardoLand on October 18, 2018, 01:23:21 PM

Title: Question about Charset Latin
Post by: RicardoLand on October 18, 2018, 01:23:21 PM
Hi all,

I have a photo. If i use the command below i can see all the accents of the Caption-Abstract

exiftool -Caption-Abstract -L teste.jpg

I tried:
%option="";
$exifTool2 = new Image::ExifTool;
$option{'charsetIPTC'}="UTF8";
$option{'charset'}="UTF8";
$status=$exifTool2->ExtractInfo(FILE,\%option);
$caption = $exifTool2->GetValue("Caption-Abstract","PrintConv"); 
print $caption

I cant see the accents.

Any ideas?
Regards
Land

Title: Re: Question about Charset Latin
Post by: Phil Harvey on October 18, 2018, 01:28:24 PM
Hi Land,

The Charset option must also be applied during GetInfo() (as mentioned in the GetInfo documentation).

Also, your command was using the -L (Latin) character set.

So your command corresponds to this code:

Code: [Select]
$exifTool2 = new Image::ExifTool;
$exifTool2->Options(Charset => 'Latin');
$status = $exifTool2->ExtractInfo(FILE);
$caption = $exifTool2->GetValue("Caption-Abstract","PrintConv"); 
print $caption

- Phil
Title: Re: Question about Charset Latin
Post by: RicardoLand on October 18, 2018, 03:01:01 PM
Sorry. I copied the wrong code. The code below still doesnt return Latin chars.

Code:
I used:
%option="";
$exifTool2 = new Image::ExifTool;
$option{'charsetIPTC'}="Latin";
$option{'charset'}="Latin";
$status=$exifTool2->ExtractInfo(FILE,\%option);
$caption = $exifTool2->GetValue("Caption-Abstract","PrintConv"); 
print $caption

In my code i have two variables. Any problem ?
$exifTool = new Image::ExifTool;   --> charset UTF8
$exifTool2 = new Image::ExifTool; --> charset Latin
Title: Re: Question about Charset Latin
Post by: Phil Harvey on October 18, 2018, 09:26:06 PM
... and it shouldn't.

If the IPTC and the ExifTool character sets are the same then no translation is done and you'll see whatever encoding was used to store the tags (which apparently isn't 'Latin', or you would be getting Latin characters).  So setting CharsetIPTC to 'Latin' is wrong.  Try setting this to 'UTF8' (although this shouldn't be necessary for your example file since the command line worked without setting this).

Did you try the code I posted?

Also, did you read FAQ 10 (https://exiftool.org/faq.html#Q10)?

There is no problem having two ExifTool objects with different options.

- Phil
Title: Re: Question about Charset Latin
Post by: RicardoLand on October 19, 2018, 09:05:39 AM
Hi Phil.

Thanks to be so friend !!!!

I have a challenge here to correct some accents in the photos. The photos are from an old system and as far as i know they are not Latin or UTF-8. I dont know what encode are used but i guess a way to correct them but it is very strange.

I am using putty with UTF-8 configuration. When i use    exiftool -Caption-abstract foleto7.jpg i dont see the accents. When i use exiftool -Caption-abstract foleto7.jpg i dont see the accents too. So i think the characters are not Latin or UTF-8.

i made some tests. If i use the command below i can see the accents. I dont know a reason to use decode.
$caption = decode("utf-8", $caption);
print $caption

But it solves my problem. If i can write this value to the iptc tag my problem is solved.

I tried $exifTool->SetNewValue("Caption-Abstract",$caption,{Replace=>1});

But the $caption variable is not written as see in the screen.

Any ideas ?

Regards
Land


Title: Re: Question about Charset Latin
Post by: Phil Harvey on October 19, 2018, 09:31:28 AM
Hi Land,

I think you want this:

Code: [Select]
$exifTool2 = new Image::ExifTool;
$exifTool2->Options(Charset => 'Latin');
$exifTool2->Options(IPTCCharset => 'UTF8');
$status = $exifTool2->ExtractInfo(FILE);
$caption = $exifTool2->GetValue("Caption-Abstract","PrintConv"); 
print $caption

This will convert a caption stored as UTF-8 to Latin for printing.

- Phil

Title: Re: Question about Charset Latin
Post by: RicardoLand on October 19, 2018, 09:52:16 AM
Hi Phil,

It solved all my problems.

Loved this line :-)))
$exifTool2->Options(IPTCCharset => 'UTF8');

Thanks a lot
Regards
Land