An Image::ExifTool equivalent of these CLI commands please?

Started by Aplonis, October 11, 2013, 01:37:14 PM

Previous topic - Next topic

Aplonis

I can issue these from Perl via system() or backticks, but surely there's an Image::ExifTool way to do it, yes?
A least a Perl procedural, or possibly object oriented way?
Below are the two in CLI format.

exiftool -trailer:all= foo.mpo -o L.jpg

exiftool foo.mpo -mpimage2 -b > R.jpg


Thanks,

Gan

Phil Harvey

Hi Gan,

Simple:

$exifTool->SetNewValue('Trailer:all' => undef);
$exifTool->WriteInfo('foo.mpo', 'L,jpg');


and

my $info = $exifTool->ImageInfo('foo.mpo','MPImage2');
open OUT, '>R.jpg';
print OUT $$info{MPImage2};
close OUT;


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

Aplonis

Somehow for me, only half of that works. Having a slight issue with the second part.

Creating the L.jpg image works fine.

       
        # How I used to extract the LEFT stereo image, abandoned in favor of pure Perl.
        # system(qq|exiftool -trailer:all= "$dir_in/$mpo" -o "$dir_out/L.jpg"|) == 0 or die "ExifTool error on image 1: $?\n";
               
        # The pure Perl way per Phil Harvey.
        $exif_tool->SetNewValue('Trailer:all' => undef);
        $exif_tool->WriteInfo("$dir_in/$mpo", "$dir_out/L.jpg");


But I get a zero-byte file for the R.jpg image.

                   
        # How I used to extract the RIGHT stereo image, abandoned in favor of pure Perl.
        # system(qq|exiftool "$dir_in/$mpo" -mpimage2 -b > "$dir_out/R.jpg"|) == 0 or die "ExifTool error on image 2: $?\n"; 
       
        # The pure Perl way per Phil Harvey.
        my $info = $exif_tool->ImageInfo("$dir_in/$mpo",'MPImage2');
        open OUT, ">$dir_out/R.jpg";
        print OUT $$info{MPImage2};
        close OUT;

Phil Harvey

You would get a zero-byte output for R.jpg if MPImage2 doesn't exist.  Use ExifTool on the .mpo to see what images are available.

But I just tried this, and the code doesn't work properly if the image does exist.  I forgot to de-reference the binary data reference.  The print line should have looked like this:

print OUT ${$$info{MPImage2}};

Without this de-reference, you would get a 22-byte (or so) output file containing something like this: "SCALAR(0x7feda3b7e850)".

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