AutorotateImageEffect.php in Imagick 8
File
src/Plugin/ImageEffect/AutorotateImageEffect.php
View source
<?php
namespace Drupal\imagick\Plugin\ImageEffect;
use Drupal\Core\Image\ImageInterface;
use Drupal\image\ImageEffectBase;
use Imagick;
class AutorotateImageEffect extends ImageEffectBase {
public function applyEffect(ImageInterface $image) {
if (!$image
->apply('autorotate')) {
$this->logger
->error('Image autorotate failed using the %toolkit toolkit on %path (%mimetype)', [
'%toolkit' => $image
->getToolkitId(),
'%path' => $image
->getSource(),
'%mimetype' => $image
->getMimeType(),
]);
return FALSE;
}
return TRUE;
}
public function transformDimensions(array &$dimensions, $uri) {
try {
$image = new Imagick($uri);
$orientation = $image
->getImageOrientation();
switch ($orientation) {
case Imagick::ORIENTATION_RIGHTTOP:
case Imagick::ORIENTATION_LEFTTOP:
case Imagick::ORIENTATION_LEFTBOTTOM:
case Imagick::ORIENTATION_RIGHTBOTTOM:
$dimensions = [
'width' => $dimensions['height'],
'height' => $dimensions['width'],
];
}
} catch (\ImagickException $e) {
$this->logger
->error('Image autorotate failed to transform dimensions for %uri: @message', [
'%uri' => $uri,
'@message' => $e
->getMessage(),
]);
}
}
}