Hi,
I saved an image in jpeg format using Photoshop after placing a small string with extended characters in every metadata field I could find, ex: à côté
When reading the metadata using the following script, I get: à côté
Surprisingly, the only exception is the URL field which is read correctly as: à côté
Is there a way to get the original data?
Here's part of my code:
# add our 'lib' directory to the include list BEFORE 'use Image::ExifTool'
BEGIN {
# get exe directory
$exeDir = ($0 =~ /(.*)[\\\/]/) ? $1 : '.';
# add lib directory at start of include path
unshift @INC, "$exeDir/lib";
# load or disable config file if specified
if (@ARGV and lc($ARGV[0]) eq '-config') {
shift;
$Image::ExifTool::configFile = shift;
}
}
use Image::ExifTool;
$exifTool = new Image::ExifTool;
$info = $exifTool->ImageInfo('pic.jpg'); # hash reference
foreach (keys %$info) {
print "$_ $$info{$_} <br>\n";
}
FAQ 10 (https://exiftool.org/faq.html#Q10) explains how special characters are handled in the various types of metadata.
- Phil
I wish I was more familiar with Perl, but I think I've got it now. I get the metadata field in question with your ExifTool script. Then I decode it as shown below.
use Encode qw(decode encode);
use Image::ExifTool;
$exifTool = new Image::ExifTool;
$info = $exifTool->ImageInfo('pic.jpg'); # hash reference
%y = %{$info};
$x = $y{"Description"};
$d = decode('UTF-8', $x,);
Ah, I see. You're using the API and want to convert the returned values from UTF-8 byte streams to native Perl strings. (I'll move this thread to the API board.)
I'm glad you figured it out. You can simplify your code a bit:
use Encode qw(decode encode);
use Image::ExifTool;
my $exifTool = new Image::ExifTool;
my $info = $exifTool->ImageInfo('pic.jpg');
my $d = decode('utf8', $$info{Description});
- Phil
Thanks again :)