Closed alexander-schranz closed 4 years ago
Do you have some basic example code?
Following should be enough to reproduce it:
$imagine = new \Imagine\Vips\Imagine();
$image = $imagine->load('fox-skater.gif');
$image->layers()->coalesce();
Thanks, could reproduce.
Can you try this branch and see if it does what you expect?
@chregu the result seems not to be correct. Its not longer animated. It seems like it did write the first layer on all other layers or something like that.
@chregu for me it looks like the current vips implementation does coalesce
on read if I use the following gif:
Which have different layers sizes (400, 280, 282, ...):
foreach ($image->layers() as $layer) {
// Output using imagick will be here 400, 280, 282, ...
// Output using vips will be here 400, 400, 400, ...
echo $layer->getSize()->getWidth());
}
$image->layers()->coalesce();
foreach ($image->layers() as $layer) {
echo $layer->getSize()->getWidth()); // will output for both adapters 400, 400, ...
}
Not sure maybe coalesce
should do nothing in the vips implementation. But maybe somebody use coalesce on custom added layers so its maybe still needed but not sure what the correct way to implement it.
Mmmh, strange that it's not animated, but you're right. vips does make all the frames the same size. I look closer into it hopefully today (regarding transparency and such)
@chregu question out of topic do you know if there is something similiar in vips like the following in imagick to get the real memory usage:
$image->getImagick()->getResource(\Imagick::RESOURCETYPE_MEMORY);
vips memory management is a little bit "complicated" due to the way it works (which also makes it much less memory hungry than imagemagick). But the best is to ask the libvips author at https://github.com/libvips/libvips (just make an issue), he's very helpful and responsive
On another topic, I improved the whole coalesce function. It's almost noop if you load a gif with vips. It only does actual coalesce if you add manually frames with a different size.
So, should be good enough now. See #9 for the actual PR
And 0.9.2 is released with those fixes
@chregu Thank you for the great support!
To manipulate animated gifs I need to call for other adapters $image->layers()->coalesce(); function so all layers are the same size so I can crop something out of that gif, but when using the vips adapter i get the following error:
PHP Version: 7.3.12 PHP Vips Version: 1.0.10 Vips Version: 8.8.4
Sadly I'm not familiar how to fix this.