How to extract metadata from a binary source such as a byte array?

Started by wulfgarpo, July 20, 2011, 08:49:01 PM

Previous topic - Next topic

wulfgarpo

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

wulfgarpo

I am using the im4java wrapper for ExifTool - I just found some information surrounding BufferedImages (read: 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.


Phil Harvey

Yes, Image::ExifTool can extract metadata from a buffered file in memory.

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

wulfgarpo

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

Phil Harvey

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