in reply to Image Xs and Ys

How about cutting your code down a bit? Also, your regex matches one or more digits in the filename, so an image called mypic1.gif will set $scale to 'mypic1.gif'. What you want is something more like:

#!/perl/bin/perl # # imagexy.pl -- script to return width and height of image(s) use strict; use warnings; use diagnostics; use Image::Size qw(:all); my $scale = ($ARGV[0] =~ /^\d+$/) ? shift : 1; for (map {glob} @ARGV) { my ($x,$y,$id) = imgsize($_); print "$_ width=",$x/$scale,"in, height=",$y/$scale,"in\n"; }

LAI
:eof

Replies are listed 'Best First'.
Re: Re: Image Xs and Ys
by hsmyers (Canon) on Jan 30, 2003 at 13:09 UTC

    Nice! One minor quibble, if $scale == 1, then result is pixels, not inches...

    --hsm

    "Never try to teach a pig to sing...it wastes your time and it annoys the pig."

      Whoops, I didn't even notice that.

      Wait... why the hell are you using inches anyway? If you're scaling the image by a factor of 3, let's say, and the image is 120*50 pixels, it'll still be 360*150 pixels. Unless $scale is dpi?

      Which, come to think of it, makes a lot of sense. Oh, I guess that's what you meant in the first place. Never mind me, I'm running low on lifeblood caffeine. But let's say the scale is specified as 1 dot per inch. (big crappy billboards or whatever) Then the measurement should be in inches.

      If this is the case, then the unit of measurement is inches if a dpi is specified, pixels otherwise, and the code is:

      # 'use's and stuff go here my ($scale, $unit) = ($ARGV[0] =~ /^\d+$/) ? (shift,"in") : (1,"px"); for (map {glob} @ARGV) { my ($x,$y,$id) = imgsize($_); print "$_ width=",$x/$scale,"$unit, height=",$y/$scale,"$unit\n"; }

      Update: just a bit of tidying


      LAI
      :eof