Get image dimensions

James picture James · Oct 8, 2010 · Viewed 109.8k times · Source

I have an url to the image, like $var = http://example.com/image.png

How do I get its dimensions to an array, like array([h]=> 200, [w]=>100) (height=200, width=100)?

Answer

Sarfraz picture Sarfraz · Oct 8, 2010

You can use the getimagesize function like this:

list($width, $height) = getimagesize('path to image');
echo "width: " . $width . "<br />";
echo "height: " .  $height;