public function AutoAspectEffect::applyEffect in Thunder 8.2
Same name and namespace in other branches
- 8.5 modules/thunder_media/src/Plugin/ImageEffect/AutoAspectEffect.php \Drupal\thunder_media\Plugin\ImageEffect\AutoAspectEffect::applyEffect()
- 8.3 modules/thunder_media/src/Plugin/ImageEffect/AutoAspectEffect.php \Drupal\thunder_media\Plugin\ImageEffect\AutoAspectEffect::applyEffect()
- 8.4 modules/thunder_media/src/Plugin/ImageEffect/AutoAspectEffect.php \Drupal\thunder_media\Plugin\ImageEffect\AutoAspectEffect::applyEffect()
- 6.2.x modules/thunder_media/src/Plugin/ImageEffect/AutoAspectEffect.php \Drupal\thunder_media\Plugin\ImageEffect\AutoAspectEffect::applyEffect()
- 6.0.x modules/thunder_media/src/Plugin/ImageEffect/AutoAspectEffect.php \Drupal\thunder_media\Plugin\ImageEffect\AutoAspectEffect::applyEffect()
- 6.1.x modules/thunder_media/src/Plugin/ImageEffect/AutoAspectEffect.php \Drupal\thunder_media\Plugin\ImageEffect\AutoAspectEffect::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
- modules/
thunder_media/ src/ Plugin/ ImageEffect/ AutoAspectEffect.php, line 24
Class
- AutoAspectEffect
- Resizes an image resource.
Namespace
Drupal\thunder_media\Plugin\ImageEffectCode
public function applyEffect(ImageInterface $image) {
$ratio_adjustment = isset($this->configuration['ratio_adjustment']) ? floatval($this->configuration['ratio_adjustment']) : 1;
$aspect = $image
->getWidth() / $image
->getHeight();
// Calculate orientation: width / height * adjustment. If > 1, it's wide.
$style_name = $aspect * $ratio_adjustment > 1 ? $this->configuration['landscape'] : $this->configuration['portrait'];
if (empty($style_name)) {
// Do nothing. just return what we've got.
return TRUE;
}
/* @var ImageStyle $style */
$style = ImageStyle::load($style_name);
if (empty($style)) {
// Required preset has gone missing?
return FALSE;
}
// Run the preset actions ourself.
foreach ($style
->getEffects() as $sub_effect) {
/* @var ImageEffectInterface $sub_effect */
$sub_effect
->applyEffect($image);
}
return TRUE;
}