Hi,
Is it possible to use the perl API to extract metadata from a binary source such as a byte array? Is this possible via the cli ExifTool?
I haven't had much experience with Perl - I would be using JNI to pass my array of bytes to the Perl API.
Kind regards,
wulfgarpro
I am using the im4java wrapper for ExifTool - I just found some information surrounding BufferedImages (read: http://im4java.sourceforge.net/docs/dev-guide.html (http://im4java.sourceforge.net/docs/dev-guide.html) -- under the heading "Using BufferedImages" -- that might solve my problem; this is a much simpler solution than trying to use JNI and the Perl API.
Yes, Image::ExifTool can extract metadata from a buffered file in memory.
- Phil
Hi Phil,
Thanks for the reply.
Having no Perl experience, how would one do this? I am just trying to write a small perl script that will read in an image file as binary data (bytes) and pass this to the ImageInfo or ExtractInfo routines.
My example code thus far is:
use Image::ExifTool;
my $exifTool = new Image::ExifTool;
my $file = "C:\\IMG_7518.JPG";
my $infoa = $exifTool->ImageInfo($file);
foreach ( keys %$infoa ) {
print "$_ => $$infoa{$_}\n";
}
open( IMAGE, $file ) || die "Can't Open $imgfile\n";
binmode(IMAGE);
my ($buf, $data, $n);
while (($n = read FILE, $data, 4) != 0) {
print ($data);
$buf .= $data;
}
#'.=' is concat
print $file .= " test";
$infob = $exifTool->ExtractInfo($buf, \%binary);
foreach ( keys %$infob ) {
print "$_ => $$infob{$_}\n";
}
close(IMAGE);
The ExtractInfo method returns nothing. Am I reading the file in correctly?
Kind regards,
wulfgarpro
Hi wulfgarpro,
The code to read the file looks OK, but you have a few problems with your ExifTool API calls:
1) You must pass a scalar reference for the file in memory. (ie. \$buf, not $buf)
2) ExtractInfo does not return an information hash. You should call ImageInfo instead.
3) What is the \%binary hash you are passing? Hash references are used to pass options to ImageInfo.
- Phil