On Mon, Feb 6, 2012 at 6:59 AM, Harry Putnam <rea...@newsguy.com> wrote:
> I've been looking around, googling for a way to extract exif info from
> images. There are many tools out there.  But I wanted to fiddle with
> the information in very specific ways.
>
> I hit on the perl module: Image-ExifTool (Phil Harvey) on cpan.
>
> However I am apparently badly misunderstanding the usages shown here:
> http://search.cpan.org/~exiftool/Image-ExifTool-8.77/lib/Image/ExifTool.pod
>
> (A few bits:
>
>  use Image::ExifTool qw(:Public);
>
>  # ---- Simple procedural usage ----
>
>  # Get hash of meta information tag names/values from an image
>  $info = ImageInfo('a.jpg');
>
>  # ---- Object-oriented usage ----
>
>  # Create a new Image::ExifTool object
>  $exifTool = new Image::ExifTool;
>
>  # Extract meta information from an image
>  $exifTool->ExtractInfo($file, \%options);
> -------        ---------       ---=---       ---------      --------
>
> But my lame attempts at using this fail miserably:
>
>  (with no attempt at pretty output)
> ------- 8< snip ---------- 8< snip ---------- 8<snip -------
> use strict;
> use warnings;
> use Image::ExifTool qw(:Public);
>
>  # Create a new Image::ExifTool object
>  my $exifTool = new Image::ExifTool;
>  my $info;
> while (<>) {
>  chomp;
>  # Extract meta information from an image
>  # $exifTool->ExtractInfo($file, \%options);
>
> $exifTool->ExtractInfo("$_");
> }
>
> print $info;
> ------- 8< snip ---------- 8< snip ---------- 8<snip -------
>
> There is not enough information in that pod page for me to understand
> how to really get at the information.  No doubt my lack of skill is
> awfully evident here.
>
> Outputs a mess:
>  ./myscript t1.jpg
> ,----
> | sh: 1: Syntax error: Unterminated quoted string
> | sh: 1: ������:+Y�0y�: not found
> | sh: 1: �: not found
> | sh: 1: Syntax error: EOF in backquote substitution
> |
> | [...]
> `----
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>

Hi Harry,
Never used this module before, but I seemed to have some luck using
the example provided:

use strict;
use warnings;
BEGIN { $Image::ExifTool::configFile = '' }
use Image::ExifTool;

# Create a new Image::ExifTool object
my $exifTool = new Image::ExifTool;
$exifTool->Options(Unknown => 1);

my $fileName = 'wood.jpg';

# Extract meta information from an image
my $info = $exifTool->ImageInfo($fileName);

my $group = '';
my $tag;
foreach $tag ($exifTool->GetFoundTags('Group0'))
{
    if ($group ne $exifTool->GetGroup($tag))
    {
        $group = $exifTool->GetGroup($tag);
        print "---- $group ----\n";
    }
    my $val = $info->{$tag};
    if (ref $val eq 'SCALAR')
    {
        if ($$val =~ /^Binary data/)
        {
            $val = "($$val)";
        }
        else
        {
            my $len = length($$val);
            $val = "(Binary data $len bytes)";
        }
    }
    printf("%-32s : %s\n", $exifTool->GetDescription($tag), $val);
}

HTH, Ken

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to