1.20.x image.gd.inc | image_gd_get_info(stdClass $image) |
Get details about an image.
Parameters
$image: An image object.
Return value
FALSE, if the file could not be found or is not an image. Otherwise, a: keyed array containing information about the image:
- "width": Width, in pixels.
- "height": Height, in pixels.
- "extension": Commonly used file extension for the image.
- "mime_type": MIME type ('image/jpeg', 'image/gif', 'image/png').
See also
Related topics
File
- modules/
system/ image.gd.inc, line 345 - GD2 toolkit for image manipulation within Backdrop.
Code
function image_gd_get_info(stdClass $image) {
$details = FALSE;
$data = @getimagesize($image->source);
if (isset($data) && is_array($data)) {
$extensions = array('1' => 'gif', '2' => 'jpg', '3' => 'png');
if (defined('IMAGETYPE_WEBP')) {
$gd_info = gd_info();
if (isset($gd_info['WebP Support']) && $gd_info['WebP Support'] == TRUE) {
// Extend mapping of constants to extensions, as the PHP and GD
// versions support WebP.
// @see https://www.php.net/manual/en/image.constants.php
$extensions['18'] = 'webp';
}
}
$extension = isset($extensions[$data[2]]) ? $extensions[$data[2]] : '';
$details = array(
'width' => $data[0],
'height' => $data[1],
'extension' => $extension,
'mime_type' => $data['mime'],
);
}
return $details;
}