I have an animated gif that is 150k in size. I read in this gif, coalesce it so I can add content, and then I optimize/merge/reconstruct the layers and write it back out. I noticed that the result file size was much larger than I expected so I tried not adding any content after I coalesced it and it still is bigger than the original file. Here is the code I'm running:
Code: Select all
$image = new Imagick("test.gif");
$image = $image->coalesceImages();
// now merge the layers
$image->mergeImageLayers(Imagick::LAYERMETHOD_OPTIMIZE);
// I also tried using the following
// $image->optimizeImageLayers();
// $image = $image->deconstructImages();
$image->writeImages("test2.gif", true);
The result is that test2.gif is around 200k, but test.gif is 150k. I've tried various optimizations, but I can't seem to get the file size to change at all so I know I'm just doing something wrong. Do optimizations needs to be applied to each frame in the animated image individually at some point? I just want to figure out how to get the new file to be approximately the same size (or even smaller) than the original file, but I'm really struggling.
I also can't figure out the difference between mergeImageLayers, optimizeImageLayers, and dconstructImages... Any help would be very much appreciated. If anyone wants to try doing this, the image I'm using is