1 image.inc image_get_info($filepath, $toolkit = FALSE)

Gets details about an image.

Backdrop supports GIF, JPG and PNG file formats when used with the GD toolkit, and may support others, depending on which toolkits are installed.

Parameters

$filepath: String specifying the path of the image file.

$toolkit: An optional image toolkit name to override the default.

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').
  • "file_size": File size in bytes.

Related topics

File

core/includes/image.inc, line 160
API for manipulating images.

Code

function image_get_info($filepath, $toolkit = FALSE) {
  $details = FALSE;
  if (!is_file($filepath) && !is_uploaded_file($filepath)) {
    return $details;
  }

  if (!$toolkit) {
    $toolkit = image_get_toolkit();
  }
  if ($toolkit) {
    $image = new stdClass();
    $image->source = $filepath;
    $image->toolkit = $toolkit;
    $details = image_toolkit_invoke('get_info', $image);
    if (isset($details) && is_array($details)) {
      $details['file_size'] = filesize($filepath);
    }
    elseif (image_is_svg($filepath)) {
      // Dimensions could be FALSE if the SVG is invalid, although we should
      // have caught that on upload.
      $dimensions = image_get_svg_dimensions($filepath);
      $details = array(
        'width' => isset($dimensions['width']) ? $dimensions['width'] : IMAGE_SVG_DEFAULT_WIDTH,
        'height' => isset($dimensions['height']) ? $dimensions['height'] : IMAGE_SVG_DEFAULT_HEIGHT,
        'extension' => 'svg',
        'mime_type' => 'image/svg+xml',
        'file_size' => filesize($filepath),
      );
    }
  }

  return $details;
}