Loads an image file and returns an image object.
Any changes to the file are not saved until image_save() is called.
string $file: Path to an image file.
\Drupal\system\Plugin\ImageToolkitInterface $toolkit: (optional) Image toolkit object to override the default.
object An image object or FALSE if there was a problem loading the file. The image object has the following properties:
Image toolkits may add additional properties. The caller is advised not to monkey about with them.
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;
}