Background.php in Image Effects 8
File
src/Plugin/ImageToolkit/Operation/gd/Background.php
View source
<?php
namespace Drupal\image_effects\Plugin\ImageToolkit\Operation\gd;
use Drupal\system\Plugin\ImageToolkit\Operation\gd\GDImageToolkitOperationBase;
use Drupal\image_effects\Plugin\ImageToolkit\Operation\BackgroundTrait;
class Background extends GDImageToolkitOperationBase {
use BackgroundTrait;
use GDOperationTrait;
protected function execute(array $arguments) {
$original_resource = $this
->getToolkit()
->getResource();
$data = [
'width' => $arguments['background_image']
->getWidth(),
'height' => $arguments['background_image']
->getHeight(),
'extension' => image_type_to_extension($this
->getToolkit()
->getType(), FALSE),
'transparent_color' => $this
->getToolkit()
->getTransparentColor(),
'is_temp' => TRUE,
];
if (!$this
->getToolkit()
->apply('create_new', $data)) {
imagedestroy($this
->getToolkit()
->getResource());
$this
->getToolkit()
->setResource($original_resource);
return FALSE;
}
$success = $this
->imageCopyMergeAlpha($this
->getToolkit()
->getResource(), $arguments['background_image']
->getToolkit()
->getResource(), 0, 0, 0, 0, $arguments['background_image']
->getWidth(), $arguments['background_image']
->getHeight(), 100);
if (!$success) {
imagedestroy($this
->getToolkit()
->getResource());
$this
->getToolkit()
->setResource($original_resource);
return FALSE;
}
$success = $this
->imageCopyMergeAlpha($this
->getToolkit()
->getResource(), $original_resource, $arguments['x_offset'], $arguments['y_offset'], 0, 0, imagesx($original_resource), imagesy($original_resource), $arguments['opacity']);
if ($success) {
imagedestroy($original_resource);
}
else {
imagedestroy($this
->getToolkit()
->getResource());
$this
->getToolkit()
->setResource($original_resource);
}
return $success;
}
}