ExifTool Forum

ExifTool => Archives => Topic started by: Archive on May 12, 2010, 08:54:32 AM

Title: NEWBIE...loading this module on a mac
Post by: Archive on May 12, 2010, 08:54:32 AM
[Originally posted by flieckster on 2009-03-16 01:42:32-07]

hi everyone, i'm a new perl user on my intel mac. I've had a problem loading the perl module for exiftool. i know exiftool is working since i can run it from the terminal window, but when i try to script "use Image::ExifTool; my computer tells me it cant find the @INC. Now i read that i can set the @INC to the location where i have the exiftool.pm but it never seems to work. Furthermore the i can't seem to install any module on my mac. it seems like its downloading them, but then i can never run them?

so my question is does any one have very specifics instructions for installing modules on a mac?
thanks!
Title: Re: NEWBIE...loading this module on a mac
Post by: Archive on May 12, 2010, 08:54:32 AM
[Originally posted by exiftool on 2009-03-16 11:26:54-07]

Hi,

If you used the Mac install technique, you must tell Perl where
to find Image::ExifTool:

Code:
BEGIN { unshift @INC, '/usr/bin/lib' }
 use Image::ExifTool;

If you use the Unix "make install" technique, the BEGIN is not
necessary.  But make sure you uninstall the Mac version if
you decide to do a "make install", otherwise you may run into
version sheer problems down the road when you update ExifTool
in one location but not the other.

See the ExifTool
installation instructions
for more details.

- Phil
Title: Re: NEWBIE...loading this module on a mac
Post by: Archive on May 12, 2010, 08:54:32 AM
[Originally posted by flieckster on 2009-03-17 11:24:55-07]

phil that worked great. do you have any advice where to begin to write my script so it globs a directory of misc image files and outputs only certian IPTC fields to a continuously growing tab delimited file?

currently i use apple script to accomplish this with this single line.
"exiftool -T -source -credit -headline -TransmissionReference -Instructions -title - ExifImageWidth - ExifImageHeight"  
thank you so much. you already answered a big perl question for me Smiley
Title: Re: NEWBIE...loading this module on a mac
Post by: Archive on May 12, 2010, 08:54:32 AM
[Originally posted by exiftool on 2009-03-17 11:36:34-07]

It sounds like the exiftool script is doing exactly what you asked
for, so I don't see why you need to write your own script.  Also,
you didn't mention if you want to do this in AppleScript or Perl script.

- Phil
Title: Re: NEWBIE...loading this module on a mac
Post by: Archive on May 12, 2010, 08:54:32 AM
[Originally posted by flieckster on 2009-03-17 11:44:39-07]

it does work in applescript but its a 2 part script. currently applescript does the logging with exiftool and the 2nd part is in perl. i'd like to just have one script that does everything so it can error handle. so i need to reproduce the script in perl.
Title: Re: NEWBIE...loading this module on a mac
Post by: Archive on May 12, 2010, 08:54:32 AM
[Originally posted by exiftool on 2009-03-17 12:18:42-07]

I'm not clear why you can't accomplish the logging with
a pipe:

Code:
exiftool -T ... DIR > out.txt

But if you want to do anything special that the exiftool script
won't do, then writing a bit of Perl is the way to go.  You will
have to learn a bit of Perl and browse through the ExifTool API
documentation.  Also, you can search this forum for a few script
examples.  I use the opendir/readdir/closedir functions to scan
directories, although Perl does support filename globbing.

- Phil
Title: Re: NEWBIE...loading this module on a mac
Post by: Archive on May 12, 2010, 08:54:32 AM
[Originally posted by flieckster on 2009-03-17 12:50:32-07]

do i have to use this

Code:
%Image::ExifTool::Shortcuts::UserDefined = (
    MyShortcut => ['exif:createdate','exposuretime','aperture'],
    MyAlias => 'FocalLengthIn35mmFormat',
);
to get all the options i want?
Title: Re: NEWBIE...loading this module on a mac
Post by: Archive on May 12, 2010, 08:54:32 AM
[Originally posted by exiftool on 2009-03-17 12:59:28-07]

No.
Title: Re: NEWBIE...loading this module on a mac
Post by: Archive on May 12, 2010, 08:54:33 AM
[Originally posted by flieckster on 2009-03-19 18:00:12-07]

hey phil,  i've gotten this far but i can't seem to get the syntax correct for you tool. can you tell me what i have wrong??

Code:
#!/usr/bin/perl -w

BEGIN { unshift @INC, '/usr/bin/lib' }

use Image::ExifTool;

my $file = "/Users/flieckb/Desktop/done/";

chdir( $file ) or die "Cant chdir to $file $!";
my(@file_list) = glob "*";
foreach my $file (@file_list){
my $info = -T -source -credit -headline -TransmissionReference  -instructions -title -ExifImageWidth -ExifImageHeight,($file);
foreach (keys %$info) {
open FILE, '>> done.txt' or die $!;
print FILE "$_ : $info->{$_}\n";
close FILE;
}}

i get these errors.

/Users/flieckb/Desktop/exiftool perl keep me:13:  Warning: Use of "-T" without parentheses is ambiguous
/Users/flieckb/Desktop/exiftool perl keep me:13:  Useless use of private variable in void context
Title: Re: NEWBIE...loading this module on a mac
Post by: Archive on May 12, 2010, 08:54:33 AM
[Originally posted by exiftool on 2009-03-19 18:15:38-07]

Wow.  I see you need a bit of help.  Try this:

Code:
#!/usr/bin/perl -w

BEGIN { unshift @INC, '/usr/bin/lib' }

use Image::ExifTool;

my $file = "/Users/flieckb/Desktop/done/";

chdir( $file ) or die "Cant chdir to $file $!";
my(@file_list) = glob "*";
my $exifTool = new Image::ExifTool;
foreach my $file (@file_list){
my @tags = qw(source credit headline TransmissionReference instructions
              title ExifImageWidth ExifImageHeight);
my $info = $exifTool->ImageInfo($file, \@tags);
foreach (keys %$info) {
open FILE, '>> done.txt' or die $!;
print FILE "$_ : $info->{$_}\n";
close FILE;
}}
#end

Reading the ExifTool API documentation should help if you have
further questions.

- Phil
Title: Re: NEWBIE...loading this module on a mac
Post by: Archive on May 12, 2010, 08:54:33 AM
[Originally posted by flieckster on 2009-03-24 12:52:23-07]

Thanks Phil, that really worked great. I tried reading the Exiftool API doc over the weekend, but i didnt get the answer i was looking for.

This works.

Code:
#!/usr/bin/perl -w

BEGIN { unshift @INC, '/usr/bin/lib' }

print "Content-Type: text/html\n\n";

use Image::ExifTool 'ImageInfo';

my $file = "/Users/flieckb/Desktop/done/";

chdir( $file ) or die "Cant chdir to $file $!";
my(@file_list) = glob "*";
my $exifTool = new Image::ExifTool;
foreach my $file (@file_list){
my @tags = qw(filename source credit headline TransmissionReference instructions title ExifImageWidth ExifImageHeight );

my $info = $exifTool->ImageInfo($file, \@tags);

foreach (keys %$info) {
open FILE, '>> /Volumes/172.25.5.227/Managers/Flieck/done.txt' or die $!;
print FILE "$info->{$_}\t";
close FILE;
}}

But the output is all one line across and doesn't break after after each completed file
i was expecting the output to look tab delimited like this.

filename source   credit headline TransmissionReference instructions title ExifImageWidth ExifImageHeight
filename source   credit headline TransmissionReference instructions title ExifImageWidth ExifImageHeight
filename source   credit headline TransmissionReference instructions title ExifImageWidth ExifImageHeight
filename source   credit headline TransmissionReference instructions title ExifImageWidth ExifImageHeight
filename source   credit headline TransmissionReference instructions title ExifImageWidth ExifImageHeight

plus the code seems to repeat its self at points when there is no information.
here's an example.

2000   Ally   Dana DeRogatis   2000   Dana DeRogatis   Ally   2910   00606562018_061.tif   
height credit   source   height   source   credit   width   filename

when i use this same statement in applescript exiftool adds "-" to missing fields whereas perl seems to duplicate?
Title: Re: NEWBIE...loading this module on a mac
Post by: Archive on May 12, 2010, 08:54:33 AM
[Originally posted by exiftool on 2009-03-24 14:27:13-07]

One difference is that the Duplicates option is disabled
by default by the exiftool application, but enabled by default
using the API.

Also when doing "keys %$info", the order of the tag keys
is not defined.  Instead, you should use "@tags".

It seems you are writing HTML format output, so you must
print a "
" after each file, or do some other HMTL formatting
to get the line breaks you want. (Similarly, you could add
a "
" in this forum to get line breaks here too.)

- Phil
Title: Re: NEWBIE...loading this module on a mac
Post by: Archive on May 12, 2010, 08:54:33 AM
[Originally posted by flieckster on 2009-03-24 16:53:05-07]

gotcha, ok that all worked except for the duplicate thing. i tried "--a" and got the same results with duplicates except for "filename". is it because exiftool is pulling more then one IPTC location?

also i took out HTML formating and just "\t\r" but its still not starting on a new line after each file.

00606562018_061.tif   filename

Dynamic=source

Dynamic=source

Dynamic=source

Flieck   =credit

Flieck   =credit

Flieck   =credit

   =headline

   =transmission ref

   =instructions

   =title

2000   =height

2000   =height

2910   =width

2910   =width

Code:
#!/usr/bin/perl -w

BEGIN { unshift @INC, '/usr/bin/lib' }

use Image::ExifTool 'ImageInfo';

my $file = "/Users/flieckb/Desktop/done/";

chdir( $file ) or die "Cant chdir to $file $!";
my(@file_list) = glob "*";
my $exifTool = new Image::ExifTool;
foreach my $file (@file_list){
my @tags = qw(filename source credit headline TransmissionReference instructions title ExifImageWidth ExifImageHeight);

my $info = $exifTool->ImageInfo($file, \@tags);

foreach (@tags) {
open FILE, '>> /Volumes/172.25.5.227/Managers/Flieck/done.txt' or die $!;
print FILE "$info->{$_}\t\r";
close FILE;
}}
Title: Re: NEWBIE...loading this module on a mac
Post by: Archive on May 12, 2010, 08:54:33 AM
[Originally posted by exiftool on 2009-03-24 17:04:11-07]

You should use "\n" for a new line.

To disable the Duplicates option via the API, you
do this:

Code:
$exifTool->Options(Duplicates => 0);

You should read the API documentation.  This is one of the
examples in the description of the "Options" function.

- Phil
Title: Re: NEWBIE...loading this module on a mac
Post by: Archive on May 12, 2010, 08:54:33 AM
[Originally posted by exiftool on 2009-03-24 17:09:22-07]

It occurs to me that maybe you are confusing the
API
documentation
with the
application
documentation
.

The options which begin with a "-" (like --a) are used
only on the command line for the application.  With the API,
you must call the
Options
function
.

- Phil
Title: Re: NEWBIE...loading this module on a mac
Post by: Archive on May 12, 2010, 08:54:33 AM
[Originally posted by flieckster on 2009-03-24 18:06:13-07]

ohhh... that makes sense. wow everything is working like it does in the commandline.... gezzz i guess i really need to learn more.

the last thing i'll bug you with is the tabbed output. when i use
Code:
\n
it still outputs like such.

00606562018_061.tif

Dynamic

Flieck

2000

2910

instead of this....

00606562018_061.tif   Dynamic   Flieck               2000   2910   

00606562018_061_pattern.tif   Dana DeRogatis   Ally               100   100

Code:
#!/usr/bin/perl -w

BEGIN { unshift @INC, '/usr/bin/lib' }

use Image::ExifTool 'ImageInfo';

my $file = "/Users/flieckb/Desktop/done/";

chdir( $file ) or die "Cant chdir to $file $!";
my(@file_list) = glob "*";
my $exifTool = new Image::ExifTool;
foreach my $file (@file_list){
my @tags = qw(filename source credit headline TransmissionReference instructions title ExifImageWidth ExifImageHeight);

$exifTool->Options(Duplicates => 0);

my $info = $exifTool->ImageInfo($file, \@tags);

foreach (@tags) {
open FILE, '>> /Volumes/172.25.5.227/Managers/Flieck/done.txt' or die $!;
print FILE "$info->{$_}\t";
close FILE;
}}
Title: Re: NEWBIE...loading this module on a mac
Post by: Archive on May 12, 2010, 08:54:33 AM
[Originally posted by exiftool on 2009-03-24 18:34:27-07]

try this:

Code:
#!/usr/bin/perl -w

BEGIN { unshift @INC, '/usr/bin/lib' }

use Image::ExifTool 'ImageInfo';

my $file = "/Users/flieckb/Desktop/done/";

chdir( $file ) or die "Cant chdir to $file $!";
my(@file_list) = glob "*";
my $exifTool = new Image::ExifTool;
open FILE, '>> /Volumes/172.25.5.227/Managers/Flieck/done.txt' or die $!;
foreach my $file (@file_list){
my @tags = qw(filename source credit headline TransmissionReference instructions title ExifImageWidth ExifImageHeight);

$exifTool->Options(Duplicates => 0);

my $info = $exifTool->ImageInfo($file, \@tags);

foreach (@tags) {
print FILE "$info->{$_}\t";
}
print FILE "\n";
}
close FILE;