class TextToWrapper in Image Effects 8
Same name in this branch
- 8 src/Plugin/ImageToolkit/Operation/gd/TextToWrapper.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\gd\TextToWrapper
 - 8 src/Plugin/ImageToolkit/Operation/imagemagick/TextToWrapper.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\TextToWrapper
 
Same name and namespace in other branches
- 8.3 src/Plugin/ImageToolkit/Operation/imagemagick/TextToWrapper.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\TextToWrapper
 - 8.2 src/Plugin/ImageToolkit/Operation/imagemagick/TextToWrapper.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\TextToWrapper
 
Defines Imagemagick Text Overlay text-to-wrapper operation.
Plugin annotation
@ImageToolkitOperation(
  id = "image_effects_imagemagick_text_to_wrapper",
  toolkit = "imagemagick",
  operation = "text_to_wrapper",
  label = @Translation("Overlays text over an image"),
  description = @Translation("Overlays text over an image.")
)
  Hierarchy
- class \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\TextToWrapper extends \Drupal\imagemagick\Plugin\ImageToolkit\Operation\imagemagick\ImagemagickImageToolkitOperationBase uses TextToWrapperTrait
 
Expanded class hierarchy of TextToWrapper
File
- src/
Plugin/ ImageToolkit/ Operation/ imagemagick/ TextToWrapper.php, line 19  
Namespace
Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagickView source
class TextToWrapper extends ImagemagickImageToolkitOperationBase {
  use TextToWrapperTrait;
  /**
   * {@inheritdoc}
   */
  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;
  }
  /**
   * Delete the image effect temporary file after it has been used.
   *
   * @param string $file_path
   *   Path of the file that is about to be deleted.
   */
  public static function deleteTempFile($file_path) {
    if (file_exists($file_path)) {
      file_unmanaged_delete($file_path);
    }
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            TextToWrapper:: | 
                  public static | function | Delete the image effect temporary file after it has been used. | |
| 
            TextToWrapper:: | 
                  protected | function | ||
| 
            TextToWrapperTrait:: | 
                  protected | function | ||
| 
            TextToWrapperTrait:: | 
                  protected | function |