public function BackgroundImageEffect::applyEffect in Image Effects 8
Same name and namespace in other branches
- 8.3 src/Plugin/ImageEffect/BackgroundImageEffect.php \Drupal\image_effects\Plugin\ImageEffect\BackgroundImageEffect::applyEffect()
- 8.2 src/Plugin/ImageEffect/BackgroundImageEffect.php \Drupal\image_effects\Plugin\ImageEffect\BackgroundImageEffect::applyEffect()
Applies an image effect to the image object.
Parameters
\Drupal\Core\Image\ImageInterface $image: An image file object.
Return value
bool TRUE on success. FALSE if unable to perform the image effect on the image.
Overrides ImageEffectInterface::applyEffect
File
- src/
Plugin/ ImageEffect/ BackgroundImageEffect.php, line 182
Class
- BackgroundImageEffect
- Class BackgroundImageEffect.
Namespace
Drupal\image_effects\Plugin\ImageEffectCode
public function applyEffect(ImageInterface $image) {
$background_image = $this->imageFactory
->get($this->configuration['background_image']);
if (!$background_image
->isValid()) {
$this->logger
->error('Image background failed using the %toolkit toolkit on %path', [
'%toolkit' => $image
->getToolkitId(),
'%path' => $this->configuration['background_image'],
]);
return FALSE;
}
list($x, $y) = explode('-', $this->configuration['placement']);
$x_pos = image_filter_keyword($x, $background_image
->getWidth(), $image
->getWidth());
$y_pos = image_filter_keyword($y, $background_image
->getHeight(), $image
->getHeight());
return $image
->apply('background', [
'x_offset' => $x_pos + $this->configuration['x_offset'],
'y_offset' => $y_pos + $this->configuration['y_offset'],
'opacity' => $this->configuration['opacity'],
'background_image' => $background_image,
]);
}