Extract JpgFromRaw or PreviewImage with Perl use Image::ExifTool API

Started by Janc, March 27, 2010, 04:46:38 PM

Previous topic - Next topic

Janc

Hi friends!

I'm trying to extract JpgFromRaw and/or JpgFromRaw with use Image::ExifTool in an aplication I'm coding.

I know how to do it with "exiftool -b -JpgFromRaw -w .JPG -r ." but I need to do it with Image::ExifTool

Please. Can you help me a little bit just how to start?

Thanks a lot in advanced.
Best regards.

Phil Harvey

A script is worth a thousand words:

#!/usr/bin/perl -w
use strict;
use Image::ExifTool;

my $file = shift or die "Please specify input RAW file name\n";
my $out = shift or die "Also specify output JPEG file name\n";
-e $out and die "Error: $out already exists\n";

my $exifTool = new Image::ExifTool;
my $info = $exifTool->ImageInfo($file,'JpgFromRaw','PreviewImage');
my $val = $$info{JpgFromRaw} || $$info{PreviewImage};
$val or die "No embedded JPG in $file\n";

open OUT, ">$out" or die "Error creating $out\n";
print OUT $$val and close OUT or die "Error writing $out\n";
print "$out written OK\n";
# end


Notice that I dereference $val because I know both JpgFromRaw and PreviewImage will return a scalar reference, but to be safe you should probably test for this.

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

Janc

Hi Phil!

A thousand thanks for your thousand words and for your superb Exiftool  :)

I'm going to code it in my script.

Edited: It is working perfectly and very fast  :D

My best regards.
Jose Angel Navarro.