Using ExifTool from my Perl script running on Apache24 on Windows7

Started by gld64, February 07, 2016, 09:11:22 AM

Previous topic - Next topic

gld64

Prior to uploading my Perl scripts to my web server, I test them on my local computer which is running Apache 2.4 on Windows 7.  I copied all the exiftool files to my C:\Apache24\cgi-bin directory, and also added the pl extension to the exiftool script. I can now successfully list every detail of my picture from the Windows command prompt by typing the following from within this cgi-bin directory:

  perl exiftool.pl pic.jpg

But I still can't get exiftool to work from my Perl scripts. I get a "500 Internal Server Error".  The README file says I should install the Image::ExifTool package to make it available for use by other Perl scripts by typing the following. But the first line says I don't have a C compiler, despite creating 3 files. As for the next lines, "make" is not a windows command. I'm assuming therefore that exiftool is not fully or properly installed.

  perl Makefile.PL
  make
  make test
  make install

Here's my simple Perl script, which fails on the use command.

#!C:/Perl64/bin/perl.exe
use Image::ExifTool qw(:Public);
print "Content-type: text/html\n\n";
print "hi";


Finally, here's part of the exiftool.pl file.  Did you mention I have to modify something in here.

BEGIN {
    # get exe directory
    $exeDir = ($0 =~ /(.*)[\\\/]/) ? $1 : '.';
    # add lib directory at start of include path
    unshift @INC, "$exeDir/lib";
    # load or disable config file if specified
    if (@ARGV and lc($ARGV[0]) eq '-config') {
        shift;
        $Image::ExifTool::configFile = shift;
    }
}


Thanks again for all information,
Guy

Phil Harvey

You don't have to build or install ExifTool to use it in your Perl scripts.  The BEGIN block in the "exiftool" script shows one way to add the necessary directory to the @INC so the ExifTool libraries will be available for your script.  In this case, @INC is set to include the "lib" directory in the same directory as the script.

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

gld64

Thanks, I think I've got it. At least it appears to work now.  Basically, I created a new Perl script and inserted your BEGIN block to allow my Perl script to access the ExifTool functionality. Here's my script with your ExifTool code inserted:


#!C:/Perl64/bin/perl.exe
use strict;
my $version = '10.10';
my ($exeDir, $exifTool, $info, %y, $x);
print "Content-type: text/html\n\n";

# ------------------------------------------------------------------------
# add our 'lib' directory to the include list BEFORE 'use Image::ExifTool'
BEGIN {
  # get exe directory
  $exeDir = ($0 =~ /(.*)[\\\/]/) ? $1 : '.';
  # add lib directory at start of include path
  unshift @INC, "$exeDir/lib";
  # load or disable config file if specified
  if (@ARGV and lc($ARGV[0]) eq '-config') {
    shift;
    $Image::ExifTool::configFile = shift;
  }
}
# ------------------------------------------------------------------------

use Image::ExifTool;
$exifTool = new Image::ExifTool;
$info     = $exifTool->ImageInfo('pic.jpg'); # hash reference

%y = %{$info};
$x = $y{"Description"};
print  "$x \n";

Phil Harvey

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