Sorry if this is already answered somewhere, but I cannot figure out how to retrieve image data using the Drupal image module in PHP. I've tried the following code:

$imageName = 'some.jpg'; // given
$path = variable_get('image_default_path', 'images') .'/';
$path .= $imageName;
$size = getimagesize($path);
$width = $size['width'];
$height = $size['height'];

However, the path doesn't seem to be correct. I've searched the forum and the image.module code, but I couldn't find any code that does exactly this.

I'm new to Drupal and sadly don't have much PHP experience either. Thanks in advance for any suggestions.

GK

Comments

g99k’s picture

Oh, I found it. There's lots of functions in the standard image toolkit in includes/image.inc. To get the image info, you have to know the node id though.

$node = node_load($node_id);
$path = file_create_path($node->images[IMAGE_ORIGINAL]);
$image_info = image_get_info($path);
// info includes width and height
$width = $image_info['width'];
$height = $image_info['height'];

With all those different image plugins, I totally overlooked the existence of the image toolkit. In case this happens to others, here's the link to the Drupal image toolkits API:

http://api.drupal.org/api/group/image/6