Win32 filenames (non latin) in perl

Started by marjue, February 18, 2014, 06:14:22 PM

Previous topic - Next topic

marjue

Hi

I have a working Perl script which is writing exif Infos to picture files.
I managed it to handle german umlaute on win7. Now i try to get it working even with non latin chars like russian.

But i have to realize that it does not work. I tried convertin the strings to/from utf-8, utf-16, cp1251 .... nothing is working.

could someone please post an example for me?

my test-code:


use Data::Dumper;
use Encode qw/encode decode/;
use Image::ExifTool;

#$filename = 'йцуке.tif';    # works not
$filename = 'äää.tif';       # works

$filename = decode('UTF8',"$filename");
$filename = encode('cp1250',"$filename");

$Data::Dumper::Useqq=1;
print Dumper($filename);

# read exif
my $exifTool = new Image::ExifTool;
my $info     = $exifTool->ImageInfo("${filename}");
   
# read metadata
my $lens = $exifTool->GetValue('LensModel');
print "$lens\n";


Yes the script is saved in utf8.


Bye
Marcus

Phil Harvey

Hi Marcus,

You need to use dedicated Win32 functions to handle special characters in file names on Windows  See this thread for some hints about this.  I think you may be able to open the file like this then pass the file handle to ExifTool.

Please let me know how it goes.

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

marjue

Hi Phil

I know how to handle normal files with a special Win32 module and it worked even with russian letters. I tested this yesterday.
But i didn't know that it is possible to use an existing Filehandle with ExfTool.

Can you give me an example how to use an existing FileHandle with ExifTool in Perl.

If it works i will post a reply.

Thank you


Edit!!!

I found it !!

my $exifTool = new Image::ExifTool;

$info = $exifTool->ImageInfo(\*FILE_PT, 'Aperture', 'ShutterSpeed', 'ISO');

marjue

I have solved it ... with some help from others found Google  :)


use Data::Dump qw(dump);
use Encode qw/encode decode/;
use Win32API::File qw(:ALL);
use Image::ExifTool;
use strict;

# Script must be saved in UTF-8


my $file        = 'йцуке.tif';


my $file_utf8   = decode('UTF-8',"$file");
my $file_utf16  = encode("UTF-16LE", $file_utf8);  # Format supported by NTFS
my $file_win    = eval dump($file_utf16);          # Remove UTF ness
   $file_win   .= chr(0).chr(0);                   # 0 terminate string
   
# Create Win Filehandle
my $win_fh  = Win32API::File::CreateFileW ($file_win, FILE_READ_DATA, 0, [], OPEN_EXISTING, 0, []); # Create file via Win32API
say $^E if $^E;                   # Write any error message

# Create Perl Filehandle
OsFHandleOpen('FILE', $win_fh, "r") or die "Cannot open file";

# read exif
my $exifTool = new Image::ExifTool;
my $info     = $exifTool->ImageInfo(\*FILE);
   
# read metadata
my $lens = $exifTool->GetValue('LensModel');
print "$lens\n";

close(FILE);


Bye
Marcus

Phil Harvey

Hi Marcus,

Great.  Thank you very much for posting your solution.

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