php-imagine / Imagine

PHP Object Oriented image manipulation library
https://imagine.readthedocs.io
Other
4.42k stars 530 forks source link

Imagine\Imagick\Imagine create gif animation - more than 200mb of memory #730

Closed goodwin74 closed 2 years ago

goodwin74 commented 4 years ago

When creating a GIF, more than 200 MB is spent and the PHP process freezes and gives a 404 error. What is the reason for this? And how to fix it? The total size of all frames (in base64) is only 10mb, where from so much memory consumption?

$imagine = new Imagine\Imagick\Imagine();
$image = '';
foreach ($framesBase64 as $frame){
 $data = explode( ',', $frame);
 $decoded = base64_decode($data[1]);
 if($image === ''){
   $image = $imagine->load($decoded);
 } else {
   $image->layers()->add($imagine->load($decoded));
 }
}
$gifdata = $image->get('gif', array(
                   'animated'       => true,
                   'animated.delay' => 40, // delay in ms
                   'animated.loops' => 0,   // number of loops, 0 means infinite
               ));
echo base64_encode($gifdata);
goodwin74 commented 4 years ago

if use GD - print error: GD does not support layer set How to use GD to make an animation? Perhaps he will eat less memory ?!

mlocati commented 2 years ago

GD does not support animated GIFs, and Imagick is a bit memory hungry. Maybe you could try with https://github.com/rokka-io/imagine-vips