Intervention / image

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

Add possibility to read/decode Image without animation #1307

Closed olivervogel closed 2 months ago

olivervogel commented 6 months ago

Describe the feature you'd like

Intervention Image 2 did not support animated GIFs. Animated images were reable, but only the first frame was processed and the rest was discarded.

Of course, this meant that the animation was lost, but in the end it also saved resources. This is particularly noticeable when using the GD driver, as animated GIFs are not natively supported here and an individual GDImage instance must be created in memory for each frame.

If you read in images without the intention of processing the animation anyway, this process is carried out for nothing. It is of course possible to discard the animation with removeAnimation() afterwards, but then the decoding process has already been carried out.

For this reason, there should be a way to ignore the animation directly during or before decoding and not even start this resource-intensive process.

Is your feature request related to a problem? Please describe.

See #1305

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 decodeAnimation option can be used to prevent animations from being read out 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,
    decodeAnimation: false,
);

// animated gif is only read with the first frame
$image = $manager->read('animation.gif');

See documentation for more details.