Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: How to read Image Resolution on Mac OS X

by frozenwithjoy (Priest)
on Oct 08, 2013 at 15:51 UTC ( [id://1057432]=note: print w/replies, xml ) Need Help??


in reply to How to read Image Resolution on Mac OS X

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;

Replies are listed 'Best First'.
Re^2: How to read Image Resolution on Mac OS X
by Jouve (Initiate) on Oct 10, 2013 at 06:30 UTC
    Hi frozenwithjoy, Thanks for your alternative solution. Thanks Sankar B

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1057432]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-26 03:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found