ExifTool Forum

ExifTool => The Image::ExifTool API => Topic started by: gld64 on February 07, 2016, 09:07:56 PM

Title: Photoshop jpeg utf-8
Post by: gld64 on February 07, 2016, 09:07:56 PM
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";
}
Title: Re: Photoshop jpeg utf-8
Post by: Phil Harvey on February 07, 2016, 09:32:10 PM
FAQ 10 (https://exiftool.org/faq.html#Q10) explains how special characters are handled in the various types of metadata.

- Phil
Title: Re: Photoshop jpeg utf-8
Post by: gld64 on February 10, 2016, 10:53:00 AM
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,);
Title: Re: Photoshop jpeg utf-8
Post by: Phil Harvey on February 10, 2016, 11:00:47 AM
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
Title: Re: Photoshop jpeg utf-8
Post by: gld64 on February 10, 2016, 12:18:54 PM
Thanks again :)