rokka-io / imagine-vips

libvips adapter for php imagine
https://rokka.io
Other
41 stars 8 forks source link

Layers::coalesce throw an error #8

Closed alexander-schranz closed 4 years ago

alexander-schranz commented 4 years ago

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:

VipsOperation: Klasse »paste« nicht gefunden VipsOperation: Class »paste« not found

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.

chregu commented 4 years ago

Do you have some basic example code?

alexander-schranz commented 4 years ago

Following should be enough to reproduce it:

$imagine = new \Imagine\Vips\Imagine();
$image = $imagine->load('fox-skater.gif');
$image->layers()->coalesce();
Example `fox-skater.gif` ![fox-skater](https://user-images.githubusercontent.com/1698337/71992655-0b741080-3236-11ea-8316-30eeb67a76df.gif)
chregu commented 4 years ago

Thanks, could reproduce.

Can you try this branch and see if it does what you expect?

https://github.com/rokka-io/imagine-vips/tree/fix-coalesce

alexander-schranz commented 4 years ago

@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.

alexander-schranz commented 4 years ago

@chregu for me it looks like the current vips implementation does coalesce on read if I use the following gif:

Rotating_earth_(large)

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.

chregu commented 4 years ago

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)

alexander-schranz commented 4 years ago

@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);
chregu commented 4 years ago

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

chregu commented 4 years ago

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.

chregu commented 4 years ago

So, should be good enough now. See #9 for the actual PR

chregu commented 4 years ago

And 0.9.2 is released with those fixes

alexander-schranz commented 4 years ago

@chregu Thank you for the great support!