anusuya has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I tried Image::info for getting resolution of tiff images, but it is not working properly. Below is the code i have used:
use Image::Info qw(image_info dim); my $info = image_info("image.tif"); if (my $error = $info->{error}) { die "Can't open image file: $error\n"; } my $res = $info->{resolution}; print $res;

But this code works fine for JPG format, please help me to resolve this problem.

Thanks in advance,
Anusuya.

Replies are listed 'Best First'.
Re: Image::info not working properly for tiff images
by Anonymous Monk on Sep 18, 2009 at 12:06 UTC

      But OP is seeking "resolution" rather than width and height. See AM's output lines 123 & 124;

      From perldoc Image::Info ( http://search.cpan.org/~gaas/Image-Info-1.16/lib/Image/Info.pm ).

      resolution
          The value of this field normally gives the physical size of the
          image on screen or paper. When the unit specifier is missing then
          this field denotes the squareness of pixels in the image.
      
          The syntax of this field is:
      
             <res> <unit>
             <xres> "/" <yres> <unit>
             <xres> "/" <yres>
      
          The <res>, <xres> and <yres> fields are numbers. The <unit> is a
          string like "dpi", "dpm" or "dpcm" (denoting "dots per
          inch/cm/meter).

      Update (at approx +12h after the above): I've tried numerous variants on OPs code (and that offered by the doc) with both .jpg and .tif. At least under W2k, those reproduced OP's problem -- to wit, that the package fails to return resolution for a tif.

      One snippet:

      my $res = $info->{resolution }; # NG for .tif and this doesn't work either {resolution res dpi } print "\t $res\n"; #line 23 # Use of uninitialized value in concatenation (.) or string at pl_ +test\796079.pl line 23.

      Feed the script above this excerpt from an array of .tif and .jpg files, and it behaves for .jpg but not for .tif.

      Also observed: the data extracted via:

      my $info = image_info($img); if (my $error = $info->{error}) { die "Can't open image file: $error\n"; } print Dumper $info;

      provides the expected info except for showing blank fields for 'YResolution' => '', and for 'XResolution' => '', when fed a .tif but provides values which match information (extracted by other means) from a .jpg.

      Bug? or just /me in over my head?