TextToWrapper.php in Image Effects 8.2
File
src/Plugin/ImageToolkit/Operation/imagemagick/TextToWrapper.php
View source
<?php
namespace Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick;
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) {
$tmp_file = \Drupal::service('file_system')
->tempnam('temporary://', 'ifx');
$gd_wrapper_destination = $tmp_file . '.png';
file_unmanaged_move($tmp_file, $gd_wrapper_destination, FILE_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)) {
file_unmanaged_delete($file_path);
}
}
}
Classes
Name |
Description |
TextToWrapper |
Defines Imagemagick Text Overlay text-to-wrapper operation. |