Viewing JPG images form a perl script

Started by BonanzaMan, February 19, 2011, 11:54:35 PM

Previous topic - Next topic

BonanzaMan

I am looping through a direcory full of JPG files and want to invoke an image viewer from for a given jpg from a perl script run from the command prompt under Windows 7 (64 bit).  Any idaes on how to do this?

Thanks,
Greg

Phil Harvey

Hi Greg,

I doesn't sound like this question has anything to do with ExifTool.  You would need an image viewing utility for this.  ExifTool if for metadata only.

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

BonanzaMan

#2
Yeah agreed Phil... not too much to do with exiftool.

In my case, I wanted a handy way to view a directory full of JPG images and update certain tags using exiftool based on what is seen in the image - as I have hundreds of images to do this with, I needed something that integrated the viewing, user input and exiftool update in one looping construct.

This has been such a helpful forum, so I thought I'd post and see what I'd get.  I reasoned that I'd be far more likely to find somebody here who knew how to do the JPG imaging from a perl script for tag updating that on other forums.

Anyway, after messing around with this for a while, this is what I came up with.  Seems to work well, but I am total perl beginner so the usual caveats apply  ;)

Feedback ("better ways", critique, etc) welcomed!

use Image::ExifTool;
use warnings;
use strict;
use Tk;
use Tk::JPEG;

my $info;
my $newimage;
my $errcode;
my $strval;
my $errorMessage;
my $warningMessage;
my $button;

# Tag value to view and update, as needed
my $tag1 = "CreateDate";

my $exifTool = new Image::ExifTool;
my $mw = new MainWindow;
$mw -> geometry ("500x400");

my @files = <*jpg>;

my $shot = $mw->Photo(-file => "");
my $smshot = $mw->Photo(-file => "");

for my $image (@files) {
  $shot->read($image);

  # make the image 33% smaller for ease of viewing
  $smshot->copy($shot, -subsample => 3,3 );
  $button = $mw->Button(-image => $smshot)->pack();

  #update the window title
  $mw->title($image);

  $mw->update;
  select(undef, undef, undef, .1);

  $info = $exifTool->ImageInfo($image);

# retained for debug purposes
#   foreach (keys %$info) {
#     print "$_ => $$info{$_}\n";
#   }

  $strval = $exifTool->GetValue($tag1);

  print "\nCurrent value for tag [$tag1]:  $strval\n";
  print "New value for tag [$tag1] <CR> to continue:  ";
  $a = <STDIN>;
  chomp($a);

  if ($a) {
    $exifTool->SetNewValue($tag1, $a);

    # create a new file name for the new file to be written
    $newimage = "A_".$image;
   
    $errcode = $exifTool->WriteInfo($image, $newimage);

    if ($errcode ne 1) {
      $errorMessage = $exifTool->GetValue('Error');
      $warningMessage = $exifTool->GetValue('Warning');
      print "\nerrcode:  $errcode\n";
      print "Error:  $errorMessage\n\n";
    }
    else {
      print "Tag [$tag1] value changed from $strval to $a\n";
      print "New image file $newimage created successfully\n\n";
    }
  }
  $shot->blank;
  $smshot->blank;
}
exit;

nikkon

Dont think i can be of any help to you ; but browzed through your code and ran it - very good
im trying to write something similar to what you did - but im by far your junior
Do you have any updated version of that code that you could post 
Hopefully sometime in future (very far in future ) i  will have a nice tool.

Somewhere on the net is an incomplete version of a swiss army knife of images
called Diagamso.pl but not all the browzers can find it
only one page long
Anyway will appreciate an updated version of this post
and thanks