1 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
- core/
modules/ system/ image.gd.inc, line 359 - 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)) {
$supported_extensions = image_get_supported_extensions();
// Only extensions that exist in GD.
$extension = image_type_to_extension($data[2], FALSE) ? : '';
// Only extensions supported by Backdrop at this time.
$extension = in_array($extension, $supported_extensions) ? $extension : '';
// Treat jpeg as jpg.
$extension = $extension == 'jpeg' ? 'jpg' : $extension;
$details = array(
'width' => $data[0],
'height' => $data[1],
'extension' => $extension,
'mime_type' => $data['mime'],
);
}
return $details;
}