image_get_info

Versions
4.6 – 6
image_get_info($file)
7
image_get_info($filepath, $toolkit = FALSE)

Get details about an image.

Return value

array containing information about the image 'width': image's width in pixels 'height': image's height in pixels 'extension': commonly used extension for the image 'mime_type': image's MIME type ('image/jpeg', 'image/gif', etc.) 'file_size': image's physical size (in bytes)

▾ 9 functions call image_get_info()

hook_prepare in 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 includes/image.inc
Crop an image using the GD toolkit.
image_gd_resize in includes/image.inc
Scale an image to the specified size using GD.
image_gd_rotate in includes/image.inc
Rotate an image the given number of degrees.
image_scale in includes/image.inc
Scales an image to the given width and height while maintaining aspect ratio.
system_theme_settings in modules/system.module
Menu callback; display theme configuration for entire site and individual themes.
user_file_download in modules/user.module
Implementation of hook_file_download().
user_validate_picture in modules/user.module
_upload_image in modules/upload.module
Check an upload, if it is an image, make sure it fits within the maximum dimensions allowed.

Code

includes/image.inc, line 91

<?php
function image_get_info($file) {
  if (!is_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;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.