Intervention / image

PHP Image Processing
https://image.intervention.io
MIT License
13.84k stars 1.5k forks source link

Automatic or manual rotation of the image according to EXIF orientation #1285

Closed olivervogel closed 2 months ago

olivervogel commented 7 months ago

Images can contain EXIF information for camera rotation. This information is read by Intervention Image and an alignment (rotation) is performed based on it. Since version 3 this happens automatically when new image instances are decoded. In version 2, the orientation had to be triggered manually using the orientate() method.

While this may seem convenient, it may not always be desirable. Especially for very large image formats, rotation can consume alot of memory and processing time, which is not always utilized. See #1278

A return to manual auto-alignment after EXIF camera rotation should be discussed.

Keep in mind that a return to manual, will be a breaking change.

What do you think?

a-shafaat commented 7 months ago

I'm not very familiar with the internal codes of Intervention Image, but I think if you use a flag/option variable with a correct default value, you can keep current behavior and avoid breaking change. something like this:

$image = $manager->read($filePath, FilePathImageDecoder::class, false) read(mixed $input, string|array|DecoderInterface $decoders = [], bool $autoExifRotate = true) OR $image = $manager->read($filePath, FilePathImageDecoder::class, ['autoExifRotate' => false]) read(mixed $input, string|array|DecoderInterface $decoders = [], array $options= ['autoExifRotate' => true])

Elycin commented 7 months ago

+1 for this.

sitenzo commented 4 months ago

Any updates on this, would love to have not autorotate my images.

olivervogel commented 2 months ago

This feature is available from version 3.7.0.

As of this version, it is possible to configure the ImageManager globally. The autoOrientation option can be used to disable automatic exif alignment in the decoding process.

Example

use Intervention\Image\ImageManager;
use Intervention\Image\Drivers\Imagick\Driver;

// disable animation decoding in config
$manager = new ImageManager(
    Driver::class,
    autoOrientation: false // disable automatically alignment based on exif data.
);

// read image is not aligned ...
$image = $manager->read('test.jpg');

// ... but can be aligned manually at a later time
$image->orient();

See documentation for more details.