SetCanvas.php in Image Effects 8
File
src/Plugin/ImageToolkit/Operation/gd/SetCanvas.php
View source
<?php
namespace Drupal\image_effects\Plugin\ImageToolkit\Operation\gd;
use Drupal\image_effects\Component\PositionedRectangle;
use Drupal\image_effects\Plugin\ImageToolkit\Operation\SetCanvasTrait;
use Drupal\system\Plugin\ImageToolkit\Operation\gd\GDImageToolkitOperationBase;
class SetCanvas extends GDImageToolkitOperationBase {
use SetCanvasTrait;
protected function execute(array $arguments) {
$original_res = $this
->getToolkit()
->getResource();
$data = [
'width' => $arguments['width'],
'height' => $arguments['height'],
'extension' => image_type_to_extension($this
->getToolkit()
->getType(), FALSE),
'transparent_color' => $this
->getToolkit()
->getTransparentColor(),
'is_temp' => TRUE,
];
if (!$this
->getToolkit()
->apply('create_new', $data)) {
return FALSE;
}
$data = [
'rectangle' => new PositionedRectangle($arguments['width'], $arguments['height']),
'fill_color' => $arguments['canvas_color'],
];
if (!$this
->getToolkit()
->apply('draw_rectangle', $data)) {
return FALSE;
}
imagealphablending($original_res, TRUE);
imagesavealpha($original_res, TRUE);
imagealphablending($this
->getToolkit()
->getResource(), TRUE);
imagesavealpha($this
->getToolkit()
->getResource(), TRUE);
if (imagecopy($this
->getToolkit()
->getResource(), $original_res, $arguments['x_pos'], $arguments['y_pos'], 0, 0, imagesx($original_res), imagesy($original_res))) {
imagedestroy($original_res);
return TRUE;
}
else {
imagedestroy($this
->getToolkit()
->getResource());
$this
->getToolkit()
->setResource($original_res);
}
return FALSE;
}
}