Convert.php in Drupal 9
File
core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Convert.php
View source
<?php
namespace Drupal\system\Plugin\ImageToolkit\Operation\gd;
class Convert extends GDImageToolkitOperationBase {
protected function arguments() {
return [
'extension' => [
'description' => 'The new extension of the converted image',
],
];
}
protected function validateArguments(array $arguments) {
if (!in_array($arguments['extension'], $this
->getToolkit()
->getSupportedExtensions())) {
throw new \InvalidArgumentException("Invalid extension ({$arguments['extension']}) specified for the image 'convert' operation");
}
return $arguments;
}
protected function execute(array $arguments) {
$width = $this
->getToolkit()
->getWidth();
$height = $this
->getToolkit()
->getHeight();
$original_resource = $this
->getToolkit()
->getResource();
$original_type = $this
->getToolkit()
->getType();
$data = [
'width' => $width,
'height' => $height,
'extension' => $arguments['extension'],
'transparent_color' => $this
->getToolkit()
->getTransparentColor(),
'is_temp' => TRUE,
];
if ($this
->getToolkit()
->apply('create_new', $data)) {
if (imagecopyresampled($this
->getToolkit()
->getResource(), $original_resource, 0, 0, 0, 0, $width, $height, $width, $height)) {
imagedestroy($original_resource);
return TRUE;
}
$this
->getToolkit()
->setResource($original_resource);
$this
->getToolkit()
->setType($original_type);
}
return FALSE;
}
}
Classes
Name |
Description |
Convert |
Defines GD2 convert operation. |