in reply to How can I get image height and width without using Image::Size?

I like Image::Size. (However, I was unable to get it working on an older RedHat system due to missing modules.) You should use it if you can because it is much more efficient, as it doesn't spawn a process. Here's how:

use Image::Size; # get the image size, and print it out my( $width, $height ) = imgsize( $imagefile_pathname );

But if you want to do it purely using a system command and ImageMagick's identify, here's how:

# (assume identify is in the path) chomp( my $ident = `identify -format "%w %h" "$imagefile_pathname"` ); my( $width, $height ) = split ' ', $ident;

Replies are listed 'Best First'.
Re: Answer: How can I get image height and width without using Image::Size?
by Tux (Canon) on Jun 26, 2007 at 07:23 UTC

    Why all those steps?

    chomp (my $id = `identify $image_file`); my ($x, $y) = ($id =~ m/\s([0-9]+)x([0-9]+)\s/);

    And yes, I also use Image::Size when available.


    Enjoy, Have FUN! H.Merijn

      This of course does not work for files that are called My pic of a 4x4 car.jpg :)

      But identify has options!

      my ($x, $y) = (`identify -format "%w,%h" -quiet $image_file` =~ m/(\d+)/g);

      In whatever prefered context or style.


      Enjoy, Have FUN! H.Merijn