image_get_info

  1. drupal
    1. 5
    2. 6
    3. 7
    4. 8
Versions
5 – 6 image_get_info($file)
8 – 7 image_get_info($filepath, $toolkit = FALSE)

Get details about an image.

Drupal 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

▾ 19 functions call image_get_info()

FileValidatorTest::testFileValidateImageResolution in modules/simpletest/tests/file.test
This ensures the resolution of a specific file is within bounds. The image will be resized if it's too large.
file_validate_image_resolution in includes/file.inc
Verify that image dimensions are within the specified maximum and minimum.
file_validate_is_image in includes/file.inc
Check that the file is recognized by image_get_info() as an image.
hook_file_download in modules/system/system.api.php
Control access to private file downloads and specify HTTP headers.
hook_prepare in modules/node/node.api.php
Act on a node object about to be shown on the add/edit form.
ImageFieldValidateTestCase::testResolution in modules/image/image.test
Test min/max resolution settings.
ImageStylesPathAndUrlUnitTest::_testImageStyleUrlAndPath in modules/image/image.test
Test image_style_url().
ImageToolkitTestCase::setUp in modules/simpletest/tests/image.test
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix.…
image_file_download in modules/image/image.module
Implements hook_file_download().
image_load in includes/image.inc
Load an image file and return an image object.
image_save in includes/image.inc
Close the image and save the changes to a file.
theme_image_style_preview in modules/image/image.admin.inc
Returns HTML for a preview of an image style.
UserPictureTestCase::testPictureIsValid in modules/user/user.test
Do the test: Picture is valid (proper size and dimension)
UserPictureTestCase::testWithGDinvalidDimension in modules/user/user.test
Do the test: GD Toolkit is installed Picture has invalid dimension
UserPictureTestCase::testWithGDinvalidSize in modules/user/user.test
Do the test: GD Toolkit is installed Picture has invalid size
UserPictureTestCase::testWithoutGDinvalidDimension in modules/user/user.test
Do the test: GD Toolkit is not installed Picture has invalid size
UserPictureTestCase::testWithoutGDinvalidSize in modules/user/user.test
Do the test: GD Toolkit is not installed Picture has invalid size
user_file_download in modules/user/user.module
Implements hook_file_download().
user_save in modules/user/user.module
Save changes to a user account or add a new user.

Code

includes/image.inc, line 124

<?php
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);
    }
  }

  return $details;
}
?>