function image_load

Loads an image file and returns an image object.

Any changes to the file are not saved until image_save() is called.

Parameters

string $file: Path to an image file.

\Drupal\system\Plugin\ImageToolkitInterface $toolkit: (optional) Image toolkit object to override the default.

Return value

object An image object or FALSE if there was a problem loading the file. The image object has the following properties:

  • 'source' - The original file path.
  • 'info' - The array of information returned by image_get_info()
  • 'toolkit' - The name of the image toolkit requested when the image was loaded.

Image toolkits may add additional properties. The caller is advised not to monkey about with them.

See also

image_save()

image_get_info()

Related topics

5 calls to image_load()
file_validate_image_resolution in drupal/core/modules/file/file.module
Verifies that image dimensions are within the specified maximum and minimum.
image_style_create_derivative in drupal/core/modules/image/image.module
Creates a new image derivative based on an image style.
image_style_deliver in drupal/core/modules/image/image.module
Page callback: Generates a derivative, given a style and image path.
ToolkitGdTest::testManipulations in drupal/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php
Since PHP can't visually check that our images have been manipulated properly, build a list of expected color values for each of the corners and the expected height and widths for the final images.
ToolkitTest::testLoad in drupal/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTest.php
Test the image_load() function.

File

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

Code

function image_load($file, ImageToolkitInterface $toolkit = NULL) {
  if ($toolkit === NULL) {
    $toolkit = Drupal::service('image.toolkit');
  }
  if ($toolkit) {
    $image = new stdClass();
    $image->source = $file;
    $image->info = image_get_info($file, $toolkit);
    if (isset($image->info) && is_array($image->info)) {
      $image->toolkit = $toolkit;
      if ($toolkit
        ->load($image)) {
        return $image;
      }
    }
  }
  return FALSE;
}