TextToWrapper.php in Image Effects 8.3
File
src/Plugin/ImageToolkit/Operation/imagemagick/TextToWrapper.php
View source
<?php
namespace Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick;
use Drupal\Core\File\FileSystemInterface;
use Drupal\image_effects\Plugin\ImageToolkit\Operation\TextToWrapperTrait;
use Drupal\imagemagick\Plugin\ImageToolkit\Operation\imagemagick\ImagemagickImageToolkitOperationBase;
class TextToWrapper extends ImagemagickImageToolkitOperationBase {
use TextToWrapperTrait;
protected function execute(array $arguments) {
$gd_wrapper = \Drupal::service('image.factory')
->get(NULL, 'gd');
$gd_wrapper
->apply('text_to_wrapper', $arguments);
if ($gd_wrapper) {
$file_system = \Drupal::service('file_system');
$tmp_file = $file_system
->tempnam('temporary://', 'ifx');
$gd_wrapper_destination = $tmp_file . '.png';
$file_system
->move($tmp_file, $gd_wrapper_destination, FileSystemInterface::CREATE_DIRECTORY);
$gd_wrapper
->save($gd_wrapper_destination);
$tmp_wrapper = \Drupal::service('image.factory')
->get($gd_wrapper_destination, 'imagemagick');
drupal_register_shutdown_function([
static::class,
'deleteTempFile',
], $gd_wrapper_destination);
return $this
->getToolkit()
->apply('replace_image', [
'replacement_image' => $tmp_wrapper,
]);
}
return FALSE;
}
public static function deleteTempFile($file_path) {
if (file_exists($file_path)) {
\Drupal::service('file_system')
->delete($file_path);
}
}
}
Classes
Name |
Description |
TextToWrapper |
Defines Imagemagick Text Overlay text-to-wrapper operation. |