You are here

protected function TextToWrapper::execute in Image Effects 8

Same name in this branch
  1. 8 src/Plugin/ImageToolkit/Operation/gd/TextToWrapper.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\gd\TextToWrapper::execute()
  2. 8 src/Plugin/ImageToolkit/Operation/imagemagick/TextToWrapper.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\TextToWrapper::execute()
Same name and namespace in other branches
  1. 8.3 src/Plugin/ImageToolkit/Operation/imagemagick/TextToWrapper.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\TextToWrapper::execute()
  2. 8.2 src/Plugin/ImageToolkit/Operation/imagemagick/TextToWrapper.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\TextToWrapper::execute()

File

src/Plugin/ImageToolkit/Operation/imagemagick/TextToWrapper.php, line 26

Class

TextToWrapper
Defines Imagemagick Text Overlay text-to-wrapper operation.

Namespace

Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick

Code

protected function execute(array $arguments) {

  // Get a temporary wrapper image object via the GD toolkit.
  $gd_wrapper = \Drupal::service('image.factory')
    ->get(NULL, 'gd');
  $gd_wrapper
    ->apply('text_to_wrapper', $arguments);

  // Flush the temporary wrapper to disk, reopen via ImageMagick and return.
  if ($gd_wrapper) {

    // Temporary file prefix is limited to 3 chars for Windows compatibility.
    $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');

    // Defer removal of the temporary file to after it has been processed.
    drupal_register_shutdown_function([
      static::class,
      'deleteTempFile',
    ], $gd_wrapper_destination);
    return $this
      ->getToolkit()
      ->apply('replace_image', [
      'replacement_image' => $tmp_wrapper,
    ]);
  }
  return FALSE;
}