protected function GDToolkitWebP::load in Picture 8
Loads a GD resource from a file.
Return value
bool TRUE or FALSE, based on success.
Overrides GDToolkit::load
File
- src/
Plugin/ ImageToolkit/ GDToolkitWebP.php, line 29 - Contains \Drupal\system\Plugin\ImageToolkit\GDToolkit.
Class
- GDToolkitWebP
- Defines the GD2 toolkit for image manipulation within Drupal.
Namespace
Drupal\picture\Plugin\ImageToolkitCode
protected function load() {
// Return immediately if the image file is not valid.
if (!$this
->isValid()) {
return FALSE;
}
switch ($this
->getType()) {
case GDToolkitWebP::IMAGETYPE_WEBP:
$function = 'imagecreatefromwebp';
break;
default:
$function = 'imagecreatefrom' . image_type_to_extension($this
->getType(), FALSE);
}
if (function_exists($function) && ($resource = $function($this
->getImage()
->getSource()))) {
$this
->setResource($resource);
if (imageistruecolor($resource)) {
return TRUE;
}
else {
// Convert indexed images to true color, so that filters work
// correctly and don't result in unnecessary dither.
$new_image = $this
->createTmp($this
->getType(), imagesx($resource), imagesy($resource));
if ($ret = (bool) $new_image) {
imagecopy($new_image, $resource, 0, 0, 0, 0, imagesx($resource), imagesy($resource));
imagedestroy($resource);
$this
->setResource($new_image);
}
return $ret;
}
}
return FALSE;
}