ExifTool Forum

ExifTool => The Image::ExifTool API => Topic started by: Janc on March 27, 2010, 04:46:38 PM

Title: Extract JpgFromRaw or PreviewImage with Perl use Image::ExifTool API
Post by: Janc on March 27, 2010, 04:46:38 PM
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.
Title: Re: Extract JpgFromRaw or PreviewImage with Perl use Image::ExifTool API
Post by: Phil Harvey on March 27, 2010, 07:12:19 PM
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
Title: Re: Extract JpgFromRaw or PreviewImage with Perl use Image::ExifTool API
Post by: Janc on March 28, 2010, 05:49:26 AM
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.