public function CollageFormatterImageEffect::applyEffect in Collage Formatter 8
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/ CollageFormatterImageEffect.php, line 30 - Contains \Drupal\collageformatter\src\Plugin\ImageEffect\CollageFormatterImageEffect
Class
- CollageFormatterImageEffect
- Description of the collageformatter image effect plugin.
Namespace
Drupal\collageformatter\Plugin\ImageEffectCode
public function applyEffect(ImageInterface $image) {
if (Unicode::strpos(FileSystem::basename($image
->getSource()), '_copy_') !== FALSE || Unicode::strpos(FileSystem::basename($image
->getSource()), '_symlink_') !== FALSE || Unicode::strpos(FileSystem::basename($image
->getSource()), '_fake_') !== FALSE) {
$dimensions = preg_replace('/.+\\/([\\d]+x[\\d]+)_(copy|symlink|fake)_.+/', '$1', $image
->getSource());
list($image_width, $image_height) = explode('x', $dimensions);
$original_image_uri = preg_replace('/(.+\\/)collageformatter\\/(.+\\/)[\\d]+x[\\d]+_(copy|symlink|fake)_(.+)/', '$1$2$4', $image
->getSource());
// If it is a fake image - we need to load the real image resource.
if (Unicode::strpos(FileSystem::basename($image
->getSource()), '_fake_') !== FALSE) {
$original_image = \Drupal::service('image.factory')
->get($original_image_uri);
$image->info = $original_image->info;
$image->resource = $original_image->resource;
}
$effect_callback = 'image_scale_and_crop_effect';
if (\Drupal::moduleHandler()
->moduleExists('focal_point')) {
$effect_callback = 'focal_point_scale_and_crop_effect';
}
if (isset($image_width) && isset($image_height)) {
return $image
->apply($effect_callback, [
'width' => $image_width,
'height' => $image_height,
]);
// return $image->scaleAndCrop($image_width, $image_height);
}
}
return FALSE;
}