function image_get_info

7.x image.inc image_get_info($filepath, $toolkit = FALSE)
6.x image.inc image_get_info($file)

Get details about an image.

Drupal only supports GIF, JPG and PNG file formats.

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

10 calls to image_get_info()
file_validate_image_resolution in drupal-6.x/includes/file.inc
If the file is an image verify that its dimensions are within the specified maximum and minimum dimensions. Non-image files will be ignored.
file_validate_is_image in drupal-6.x/includes/file.inc
Check that the file is recognized by image_get_info() as an image.
hook_prepare in documentation-6.x/developer/hooks/node.php
This is a hook used by node modules. It is called after load but before the node is shown on the add/edit form.
image_gd_crop in drupal-6.x/includes/image.gd.inc
Crop an image using the GD toolkit.
image_gd_resize in drupal-6.x/includes/image.gd.inc
Scale an image to the specified size using GD.

... See full list

File

drupal-6.x/includes/image.inc, line 115
API for manipulating images.

Code

function image_get_info($file) {
  // Proceed no further if this file doesn't exist. Some web servers (IIS) may
  // not pass is_file() for newly uploaded files, so we need two checks here.
  if (!is_file($file) && !is_uploaded_file($file)) {
    return FALSE;
  }

  $details = FALSE;
  $data = @getimagesize($file);
  $file_size = @filesize($file);

  if (isset($data) && is_array($data)) {
    $extensions = array('1' => 'gif', '2' => 'jpg', '3' => 'png');
    $extension = array_key_exists($data[2], $extensions) ? $extensions[$data[2]] : '';
    $details = array('width' => $data[0],
      'height' => $data[1],
      'extension' => $extension,
      'file_size' => $file_size,
      'mime_type' => $data['mime']);
  }

  return $details;
}