image_get_info

  1. drupal
    1. drupal6
    2. drupal7
Versionen
drupal6 image_get_info($file)
drupal7 image_get_info($filepath)

Get details about an image.

Drupal only supports GIF, JPG and PNG file formats.

Übergabeparameter

$filepath String specifying the path of the image file.

Rückgabewert

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.

Verwandte Themen

▾ 15 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
If the file is an image verify that its dimensions are within the specified maximum and minimum dimensions.
file_validate_is_image in includes/file.inc
Check that the file is recognized by image_get_info() as an image.
hook_prepare in modules/node/node.api.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.
ImageToolkitTestCase::setUp in modules/simpletest/tests/image.test
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.
UserPictureTestCase::saveUserPicture in modules/user/user.test
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
Implementation of 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 117

<?php
function image_get_info($filepath) {
  if (!is_file($filepath)) {
    return FALSE;
  }

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

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

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen