(PECL imagick 2, PECL imagick 3)

Imagick::optimizeImageLayersRemoves repeated portions of images to optimize


public Imagick::optimizeImageLayers(): bool

Compares each image the GIF disposed forms of the previous image in the sequence. From this it attempts to select the smallest cropped image to replace each frame, while preserving the results of the animation. This method is available if Imagick has been compiled against ImageMagick version 6.2.9 or newer.


This function has no parameters.

Return Values

Returns true on success.


Throws ImagickException on error.


Example #1 Using Imagick::optimizeImageLayers()

Reading, optimizing and writing a GIF image

/* create new imagick object */
$im = new Imagick("test.gif");

/* optimize the image layers */

/* write the image back */
$im->writeImages("test_optimized.gif", true);

See Also

add a note

User Contributed Notes 1 note

f21 dot groups at gmail dot com
10 years ago
In imagick 3.x (have not checked 2.x), this returns an imagemagick object and not a boolean.


= new Imagick('myanimation.gif');

$image = $image->optimizeImageLayers(); //Does not return a boolean!

To Top