From Image::Size to Image::Magick

I recently moved a site from a shared server that had the Perl library Image::Size installed to one that had Image::Magick. Though Magick has more commands, I had trouble finding a relatively simple function: image size. I wanted to get the image dimensions so that I could create a floating div appropriately sized to an image’s dimensions. After many attempts at Googling and experimentation, I finally found the answer in the Get command. I hope you find this tip useful.

use Image::Magick;
$image = Image::Magick->new;
($width, $height) = imgsize("$file");

sub imgsize {
$image->Read(@_[0]);
$height = $image->Get('height');
$width = $image->Get('width');
return ($width,$height);
}

Comments are closed.