ExifTool Forum

ExifTool => The Image::ExifTool API => Topic started by: wulfgarpo on July 20, 2011, 08:49:01 PM

Title: How to extract metadata from a binary source such as a byte array?
Post by: wulfgarpo on July 20, 2011, 08:49:01 PM
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
Title: Re: How to extract metadata from a binary source such as a byte array?
Post by: wulfgarpo on July 20, 2011, 08:56:39 PM
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.

Title: Re: How to extract metadata from a binary source such as a byte array?
Post by: Phil Harvey on July 21, 2011, 07:35:10 AM
Yes, Image::ExifTool can extract metadata from a buffered file in memory.

- Phil
Title: Re: How to extract metadata from a binary source such as a byte array?
Post by: wulfgarpo on July 25, 2011, 03:39:08 AM
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
Title: Re: How to extract metadata from a binary source such as a byte array?
Post by: Phil Harvey on July 25, 2011, 07:33:08 AM
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