You are here

protected function TextOverlayImageEffect::getTextWrapper in Image Effects 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/ImageEffect/TextOverlayImageEffect.php \Drupal\image_effects\Plugin\ImageEffect\TextOverlayImageEffect::getTextWrapper()
  2. 8.2 src/Plugin/ImageEffect/TextOverlayImageEffect.php \Drupal\image_effects\Plugin\ImageEffect\TextOverlayImageEffect::getTextWrapper()

Get the image containing the text.

This is separated from ::applyEffect() so that it can also be used by the ::transformDimensions() method.

2 calls to TextOverlayImageEffect::getTextWrapper()
TextOverlayImageEffect::applyEffect in src/Plugin/ImageEffect/TextOverlayImageEffect.php
Applies an image effect to the image object.
TextOverlayImageEffect::transformDimensions in src/Plugin/ImageEffect/TextOverlayImageEffect.php
Determines the dimensions of the styled image.

File

src/Plugin/ImageEffect/TextOverlayImageEffect.php, line 930

Class

TextOverlayImageEffect
Overlays text on the image, defining text font, size and positioning.

Namespace

Drupal\image_effects\Plugin\ImageEffect

Code

protected function getTextWrapper() {

  // If the effect is executed outside of the context of Textimage
  // (e.g. by the core Image module), then the text_string has not been
  // pre-processed to translate tokens or apply text conversion. Do it here.
  $textimage_factory = $this
    ->getTextimageFactory();
  if (!$textimage_factory || $textimage_factory
    ->getState('building_module') !== 'textimage') {

    // Replace any tokens in text with run-time values.
    $this->configuration['text_string'] = $this->token
      ->replace($this->configuration['text_string']);

    // Let modules alter the text as needed.
    $this->configuration['text_string'] = $this
      ->getAlteredText($this->configuration['text_string']);
  }

  // Create the wrapper image object from scratch.
  $wrapper = $this->imageFactory
    ->get();

  // Return the wrapper built by the toolkit operation.
  $ret = $wrapper
    ->apply('text_to_wrapper', [
    'font_uri' => $this->configuration['font']['uri'],
    'font_size' => $this->configuration['font']['size'],
    'font_angle' => $this->configuration['font']['angle'],
    'font_color' => $this->configuration['font']['color'],
    'font_stroke_mode' => $this->configuration['font']['stroke_mode'],
    'font_stroke_color' => $this->configuration['font']['stroke_color'],
    'font_outline_top' => $this->configuration['font']['outline_top'],
    'font_outline_right' => $this->configuration['font']['outline_right'],
    'font_outline_bottom' => $this->configuration['font']['outline_bottom'],
    'font_outline_left' => $this->configuration['font']['outline_left'],
    'font_shadow_x_offset' => $this->configuration['font']['shadow_x_offset'],
    'font_shadow_y_offset' => $this->configuration['font']['shadow_y_offset'],
    'font_shadow_width' => $this->configuration['font']['shadow_width'],
    'font_shadow_height' => $this->configuration['font']['shadow_height'],
    'layout_padding_top' => $this->configuration['layout']['padding_top'],
    'layout_padding_right' => $this->configuration['layout']['padding_right'],
    'layout_padding_bottom' => $this->configuration['layout']['padding_bottom'],
    'layout_padding_left' => $this->configuration['layout']['padding_left'],
    'layout_x_pos' => $this->configuration['layout']['x_pos'],
    'layout_y_pos' => $this->configuration['layout']['y_pos'],
    'layout_x_offset' => $this->configuration['layout']['x_offset'],
    'layout_y_offset' => $this->configuration['layout']['y_offset'],
    'layout_background_color' => $this->configuration['layout']['background_color'],
    'layout_overflow_action' => $this->configuration['layout']['overflow_action'],
    'text_maximum_width' => $this->configuration['text']['maximum_width'],
    'text_fixed_width' => $this->configuration['text']['fixed_width'],
    'text_align' => $this->configuration['text']['align'],
    'text_line_spacing' => $this->configuration['text']['line_spacing'],
    'text_string' => $this->configuration['text_string'],
    'debug_visuals' => isset($this->configuration['debug_visuals']) ? $this->configuration['debug_visuals'] : FALSE,
    'canvas_width' => $this->info['image_width'],
    'canvas_height' => $this->info['image_height'],
  ]);
  return $ret ? $wrapper : NULL;
}