Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

ExifTool & system()

by aplonis (Pilgrim)
on Oct 11, 2013 at 14:59 UTC ( #1057901=perlquestion: print w/replies, xml ) Need Help??

aplonis has asked for the wisdom of the Perl Monks concerning the following question:

Scratching my head over why I get "No such file or directory" errors from "warn" on each of the system() calls in the program below...this even though the program still works.

Also I'd very like to know how to perform the first two via Image::ExifTool rather than a system() call.

#!/usr/bin/perl -w # Split_MPO.pl, Version 2013-10-11 by Gan Uesli Starling # A program to separate MPO files into a conjoined stereo pair with bo +rder around each frame. # Requires both ExifTool and ImageMagick to be installed in system. use Image::ExifTool qw(:Public); # Below are user options; my $directory = './'; my $border = 2; # Number of pixels to add as border around each frame. my $border_color = 'DarkRed'; # Color of border to add. my $view_style = 'crosseye'; # Options are 'crosseye' and 'straight'; $exif_tool = new Image::ExifTool; # Below are internal variables; my $re_filetype = '^.*.(mpo|MPO)$'; # RegEx for how to recognized an M +PO file. my %placement = ( crosseye => 'R.jpg L.jpg', straight => 'L.jpg R.jpg' +); # Order of placement for left & right frames; my %prefix_id = ( crosseye => 'X', straight => 'S'); # Naming prefix f +or output files acccording to placement of left & right frames; # Get a list of all *.mpo files, then split & rejoin each one. sub split_mpo_files { my ($dir, $re_hunt, $border, $view_style) = @_; my @file_list = hunt_files($dir, $re_hunt); for my $mpo (@file_list) { $exif_tool->ExtractInfo($mpo, []); my $geometry = add_border( $exif_tool->GetValue('ImageWidth', 'PrintConv'), + $exif_tool->GetValue('ImageHeight', 'PrintConv'), $border ); my $stereo = output_name($mpo, $prefix_id{$view_style}); # Gen +erate output filename. for ( "L.jpg", "R.jpg") {unlink $_}; # Delete temporaary files +. print "Splitting $mpo into $stereo\n"; # Extract main (left) image. # Issued via CLI because I've not yet puzzled this out the Per +lish way. system("exiftool -trailer:all= $mpo -o L.jpg") or warn("ExifTool error on image 1: $!") ; # Extract second (right) image. system("exiftool $mpo -mpimage2 -b > R.jpg") or warn("ExifTool error on image 2: $!") ; # Generate the stereo image via ImageMagick # Issued via CLI because Image::Magick would not install into +64-bit Strawberry Perl on Win7. system("montage -tile 2x0 -border $border -bordercolor $border +_color -background $border_color -geometry $geometry $placement{$view +_style} $stereo") or warn ("ImageMagick error on montage: $!") ; last; } } # Return a lists of files from path that match a RegEx. sub hunt_files { my ($path, $re) = @_; my @list; opendir ( my $dh, $path ) || die "Error in opening dir $path\n"; while( (my $file = readdir( $dh ))){ push @list, $file if $file =~ m/$re/; } closedir($dh); return @list; } # Increase geometry of single frame by the border to be added. sub add_border { my ($x, $y, $border) = @_; my @new; for ($x, $y) {push @new, $_ + $border * 2} return join('x', @new); } # Create a name for the stereo output file; sub output_name { my ($name, $prefix_id) = @_; $name =~ s{\.(mpo|MPO)$}{.jpg}; return $prefix_id . '_' . $name; } # Perform the split on all matching files in given directory. split_mpo_files( $directory, $re_filetype, $border, $view_style ); print "All done!\n"; sleep 5;

Replies are listed 'Best First'.
Re: ExifTool & system()
by toolic (Bishop) on Oct 11, 2013 at 16:34 UTC
Re: ExifTool & system()
by MidLifeXis (Monsignor) on Oct 11, 2013 at 15:02 UTC

    Check what system returns. I don't think it is what you are expecting.

    --MidLifeXis

      So I swapped each of the three system() calls for backticks like the following...

      # Extract main (left) image. my $fdbk = qx|exiftool -trailer:all= $mpo -o $dir_in/L.jpg 2>&1 1>/dev +/null|; print "ExifTool error on image 1: $fdbk\n" if $fdbk;

      ...and no error prints from the print() command but nevertheless I get three prints of just plain...

      "The system cannot find the path specified"

      ...in the CLI all by themselves. And the program still works. What am I failing to understand still yet?

Re: ExifTool & system()
by aplonis (Pilgrim) on Oct 11, 2013 at 17:28 UTC

    Okay, so now I change the calls to be like so...

    # Extract main (left) image. qx|exiftool -trailer:all= $mpo -o L.jpg 2>&1 1>/dev/null|; print "ExifTool error on image 1: $?\n" if $?;

    ...and now get feedbacks of...

    The system cannot find the path specified. ExifTool error on image 1: 256

    ...and yet STILL the program works!

    PS:

    Admittedly my present job has kept me long away from Perl. I use it but seldom now and so have grown rusty. Once I had used to sometimes answer for other people in the same way my own questions had once upon a time used to get answered. When I knew how to do it, I would answer thus, saying...

    It will work if you do it like so. Here's a simplified example.

    Basic courtesy that would be...or so seems to me. Perhaps I'm suffering a false nostalgia but having my ignorance (which is presumed in posing any question) rubbed in leaves me to feel as if the culture may have changed here?

Re: ExifTool & system()
by aplonis (Pilgrim) on Oct 11, 2013 at 18:31 UTC
    This way seems to work out best...
    # Extract main (left) image. system("exiftool -trailer:all= foo.mpo -o L.jpg") == 0 or warn "ExifTool error on image 1: $?\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1057901]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2019-07-22 09:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If you were the first to set foot on the Moon, what would be your epigram?






    Results (12 votes). Check out past polls.

    Notices?