I'm getting some inconsistency with the autorotate functionality of Stapler, and was hoping someone could explain what's happening.
My styles are defined as follows on an Eloquent model:
'styles' => [
'thumbnail' => [
'dimensions' => '300',
'auto_orient' => true,
'convert_options' => ['quality' => 100],
],
'standard' => [
'dimensions' => 'x275',
'auto_orient' => true,
'convert_options' => ['quality' => 100],
],
'zoom' => function($file, $imagine) {
$image = $imagine
->setMetadataReader(new \Imagine\Image\Metadata\ExifMetadataReader)
->open($file->getRealPath());
// Auto rotate the image
$filter = new \Imagine\Filter\Basic\Autorotate;
$filter->apply($image);
// Get the current size
$size = $image->getSize();
// Scale down to zoom size only if
// image is wide enough.
if ($size->getWidth() > 1280) {
$newSize = $size->widen(1280);
$image->resize($newSize);
}
return $image;
}
]
The issue is that, for a particular image, the zoom
style is not working correctly. It's rotating the image 90 degrees, even though the original is already upright.
Here's a screenshot of the original image, you can see it's upright:
Here's a screenshot of the image after being processed by the zoom
style. It's rotated 90 degrees:
As you can see, I also have autorotate
set to true for the thumbnail
and standard
styles, but those images are not being rotated 90 degrees and appear correctly after processing.
The strange thing is that when I check the exif orientation data for the original image, it has a value of 6, which means the image should be rotated 90 degrees. If that's the case, why do the other styles not get rotated also?
$imagine = new Imagine\Imagick\Imagine;
$image = $imagine->open('https://s3.amazonaws.com/path/to/original/image.jpg');
echo $image->metadata()->toArray()['ifd0.Orientation'];
// Output is 6
So I am wondering why the exif orientation is 6 if this image is already upright. Also, why is the image only getting rotated for the zoom
style?
Looks like I needed to return $image->strip()
in order to remove the exif data after auto rotating the image.