Wednesday, July 26, 2006

PHP : Getting image size

PHP has a very handy function getimagesize() which returns an array of values like width, height, type etc.

Example

$image_size = getimagesize("path/to/the/image.jpg"); ## URLs can also be passed

$image_size[0] is the width and $image_size[1] is the height of the image.

You can also use the following line (picked from php.net) so as to get the values in four different variables directly with the use of list() function.

list($width, $height, $type, $attr) = getimagesize( "img/flag.jpg");

No comments: