Animated GIF Assistance

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
jshirley

Animated GIF Assistance

Post by jshirley »

I'm asking this under PerlMagick since that is what I'm using, but it is more general purpose. We're working on software to layer images, some of which are animated GIFs. I think I'm failing to understand some specifics of certain types of animated GIFs, and how to implement the stacking properly, and was hoping the fine folks here could provide some insight. I've read through the examples, but I'm still not 100% clear.

I have this image I'm testing with:
Image

The incorrect output is with the first (failing to properly clear the previous frame):
Image

(This works fine with a variety of other images, though)

I'm sure it's just something trivial, and the various complexities of the background attribute is stumping me. Any insights, fixes lessons are much appreciated -- been staring at the examples section for a while and it still hasn't "clicked".

Thanks!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Animated GIF Assistance

Post by anthony »

You don't specifically say what you are trying to do! Add a solid color background, or an image, or something else.

The solutions I have are for the command line, but they should all be able to be converted to equivalent PerlMagick API calls.

Look at 'Flattening Animations', in IM Examples
http://www.imagemagick.org/Usage/anim_mods/#flatten

Coalescing the animation first then using "-border 0" to before re-optimizing the animation is the accepted way to do it under IM.

You can also add a static background using the NEW -layers composite method.
http://www.imagemagick.org/Usage/anim_mods/#background

Or underlay a background using -draw on older IM's.
http://www.imagemagick.org/Usage/anim_m ... mpose_draw
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
jshirley

Re: Animated GIF Assistance

Post by jshirley »

Ah, sorry about the confusion there.

I'm simply trying to apply the animated GIF I posted to the top of the background image (the orange cube with the dimensions, really just any arbitrary image)

That GIF (and a few others) don't clear the frames and instead layer right on top of each other. I'm trying to figure out exactly what causes that in the format itself.

So, basically, what I meant was this (stupidly I never tried the simple approach from the Examples):
convert -size 300x300 plasma:fractal null: \( images/graphics/chainplaya.gif -coalesce \) -layers Composite -gravity Center -layers Optimize t/output/output.gif
Output:
Image

If you note the difference between the animated stamps here, and then on previous image, the background doesn't seem to be clearing. The Optimize layers seems to be the reason for that.

The problem here is that when doing the same via PerlMagick, I'm unsure of the ->Layers(...) syntax.

There was another post that addressed the issue I'm facing with that, in that it says "Usage: Layers(ref)" for anything I feed into it. That post said it was due to be fixed in 6.3.5 beta -- but given that we're hitching into a lot of IM functionality outside of this project I don't feel comfortable installing a beta for the fix (nor am I exactly sure what is happening)

I'd really love to get an understanding of what makes this animated GIF different than the others that we're using that don't have any issue (and to get it working :))

PS., we're using IM 6.3.3 right now.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Animated GIF Assistance

Post by anthony »

It is a lot better, though some parts of the background does not seem to clear properly (look at the right part of background uncovered by the swing). Looks like you have some color optimization problems, You probably need to use a +map
to force the use of a common color map. But all in all it looks quite good.
jshirley wrote:The problem here is that when doing the same via PerlMagick, I'm unsure of the ->Layers(...) syntax.
Can't help you there. I wrote the magick core function, designing it accept two separate image sequences, (one sequence in this case is a static image, which is a special case, see IM example notes). Only the command line does a 'null:' iamge separation as the command line can only use one active image sequence at a time.

API's can have multiple image sequences, or 'wands'. So it probably wants two separate images sequences, somehow.
jshirley wrote:There was another post that addressed the issue I'm facing with that, in that it says "Usage: Layers(ref)" for anything I feed into it. That post said it was due to be fixed in 6.3.5 beta -- but given that we're hitching into a lot of IM functionality outside of this project I don't feel comfortable installing a beta for the fix (nor am I exactly sure what is happening)
The 6.3.5 is due out friday US time. I have given my OKay for bug checks just a couple of hours ago. My bug check as ALL IM examples, the results of which are now updated and online. that is the images results you see in IM exmaples, is really the image that was just generated with the new impending release.
="jshirley"I'd really love to get an understanding of what makes this animated GIF different than the others that we're using that don't have any issue (and to get it working :))
Look at the IM Examples, Basics, which goes though the nitty-griity about Animations, and how they differ, and how you can see what they really look like internally.

For example I provide a script "gif_anim_monatge" that shows what is in an animation and there placement, either with or without coalescing.
See http://www.imagemagick.org/Usage/anim_basics/#montage
for examples of what it outputs.

PS., we're using IM 6.3.3 right now.[/quote]
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Animated GIF Assistance

Post by anthony »

Look like the manual does not list Layers Composite yet. It may not have been implemented in that API as yet. It is rather new after all.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
jshirley

Re: Animated GIF Assistance

Post by jshirley »

anthony wrote:Look like the manual does not list Layers Composite yet. It may not have been implemented in that API as yet. It is rather new after all.
That looks to be the case. $image->Layers( method => Optimize ); works with 6.3.5 but $image->Layers( method => Composite ); aborts with:

Code: Select all

Assertion failed: (method == CompareAnyLayer || method == CompareClearLayer || method == CompareOverlayLayer), function CompareImageLayers, file magick/layer.c, line 760.
Abort trap: 6 (core dumped)
This command line works like a champ:

Code: Select all

convert images/bitmap_background.jpg null: \( images/graphics/chainplaya.gif -coalesce \) -gravity Center -layers Composite -layers Optimize t/output/composite_background.gif
It generates (correct):
Image

Without the ->Layers( method => 'Composite' ) in PerlMagick, the best I can (still) get seems to be:
Image

If I'm understanding properly, the specific GIF I'm using has a background frame that isn't being properly disposed. The composite call on the layers should resolve that, which doesn't exist in the Perl API at the moment.

Can you confirm that my understanding is correct?

And the GIF overlay is at Image

(PS., Thanks very much for the help and links... I've been neck deep in the IM examples and trying to figure out all this -- a bit of a learning curve, and you've been great!)
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Animated GIF Assistance

Post by anthony »

Report a bug for the missing method in the bugs forum.

That is exactly what is going on. Implementation is probably a little trickier as the API version should allow you to give it a second 'Wand' or image image. An API should not need you to append the lists together with a 'null:' marker.

On the other had the operation has alwasy been a good one for API's to implement themselves. All it is a 'composite' of each pair of images from each list, with special case for one of the two lists being 'empty'.

That is loop through the images yourself and overlay the lists.


This trickyness of needing two lists may mean a new Perl API function will be needed, or a expandsion of the old function with a options second part for that
layers method.

Note that another two list, layers method is also planned to merge two animations
with appropriate time wise frame additions.
See IM Examples... Merging Time Disjoint Animations
http://www.imagemagick.org/Usage/anim_mods/#merge

In any case while I created the MagickCore function, and the Command line interface, I have no idea how the Perl API or even the MagickWand APIs should be modified to handle this method. Report a bug, in that it is not available.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply