Get Image Height and Width as integer values?

php

Question

I've tried to use the PHP function getimagesize, but I was unable to extract the image width and height as an integer value.

How can I achieve this?

1
91
9/18/2012 10:57:48 AM

Accepted Answer

Try like this:

list($width, $height) = getimagesize('path_to_image');

Make sure that:

  1. You specify the correct image path there
  2. The image has read access
  3. Chmod image dir to 755

Also try to prefix path with $_SERVER[DOCUMENT_ROOT], this helps sometimes when you are not able to read the files

183
8/24/2015 1:26:29 PM

list($width, $height) = getimagesize($filename)

Or,

$data = getimagesize($filename);
$width = $data[0];
$height = $data[1];

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon