Let Image::ExifTool do the work. No need using a regex to extract the resolution. I've written a script to extract metadata from images (on OS X). It is located in one of my GitHub repos along with other related scripts. By default, it only outputs the subset of exif data that I was interested in, but you can make the appropriate changes to extract what you'd like (or use the --all option to output all exif data).

The pertinent code + output:

#!/usr/bin/env perl use strict; use warnings; use feature 'say'; use Data::Printer; use Image::ExifTool qw(:Public); my $image = $ARGV[0]; my $exif = ImageInfo( $image, 'XResolution', 'YResolution' ); p $exif; my $xrez = $$exif{'XResolution'}; my $yrez = $$exif{'YResolution'}; say "Resolution is $xrez x $yrez."; __END__ \ { XResolution 180, YResolution 180 } Resolution is 180 x 180.

The full script:

#!/usr/bin/env perl # exif_extractor.pl use strict; use warnings; use Data::Printer; use Image::ExifTool qw(:Public); use Getopt::Long; my ( $image, $all, $help ); my $options = GetOptions( "image=s" => \$image, "all" => \$all, "help" => \$help, ); my $usage = <<USAGE_END; USAGE: $0 --image Image name --all Extract all Metadata by default, extracts: * CreateDate * Directory * FileName * FileNumber * MeasuredEV * OwnerName --help USAGE_END die "**NO IMAGE SPECIFIED**\n" . $usage unless $image; die $usage if $help; if ($all) { p ImageInfo($image); } else { p ImageInfo( $image, 'CreateDate', 'Directory', 'FileName', 'FileNumber', 'MeasuredEV', 'OwnerName' ); } exit;

In reply to Re: How to read Image Resolution on Mac OS X by frozenwithjoy
in thread How to read Image Resolution on Mac OS X by Jouve

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.