Page 1 of 1

Compose one animation over another

Posted: 2008-09-03T13:02:11-07:00
by StephenP
Hi all,
I'm having a bit of trouble with putting an animated GIF over another animated GIF. I've got it so that I can overlay an animation over a static image, but then I want to make an animated 'border' for the image, but I can't. Inexplicably, my code worked for a bit, then stopped working - maybe I changed something by accident? Anyways, here's the code, please tell me if you can see me doing anything wrong.

Basically, what I'm trying to do is this:
1) Take a PNG image [created by PHP]
2) Overlay a transparent animated GIF over that PNG [this part works fine]
3) Overlay the animation from step two over a slightly larger, glittery animation, so as to create a border effect.

Code: Select all

	shell_exec("convert glitter/".$_REQUEST['glitter']." -virtual-pixel tile -set option:distort:viewport ".$w."x".$h." -distort SRT 0 tile".$r.".gif"); //the transparent gif

	shell_exec("convert -size ".$w."x".$h." png_temp".$r.".png null: tile".$r.".gif -gravity Center -layers Composite -layers Optimize png".$r.".gif"); //transparent GIF over PNG - works fine
	if($_REQUEST['b'] != "none") // if a border was requested
	{
		shell_exec("convert border/".$_REQUEST['b']." -virtual-pixel tile -set option:distort:viewport ".($w+20)."x".($h+20)." -distort SRT 0 tile".$r.".gif"); //create the background animation
		shell_exec("convert -size ".($w+20)."x".($h+20)." tile".$r.".gif null: png".$r.".gif -gravity Center -layers Composite -compose src-over png".$r.".gif"); //animation 1 over the background animation
    }
However, it doesn't work properly - what I get instead of the mostly solid animation over the glittery one is that the background flickers back and forth between covering and uncovering the foreground image.

I think it might be an issue with how I'm using -layers and -compose, but I'm just at a loss :(
Thanks in advance,
Stephen

Re: Compose one animation over another

Posted: 2008-09-03T15:42:10-07:00
by fmw42
This topic has been discussed before. Suggest you search the archives. But here is one that I recall was discussed before. Read Anthony's comments and look at his examples. Note that it is important that the two animations have the same number of frames and also have the same delays per frame; otherwise it becomes much harder.

viewtopic.php?f=1&t=10510&hilit=composite+animation

On quick examination of your code (I am not a PHP person), put the -compose src_over BEFORE the -layers composite.

Re: Compose one animation over another

Posted: 2008-09-03T16:09:23-07:00
by StephenP
Thanks for finding that, I'll try it out and report back. :)

-Stephen

Re: Compose one animation over another

Posted: 2008-09-03T16:14:18-07:00
by anthony
merging (overlaying) two animations has one aspect which you have not mentioned.

Timing.

The -layers composite merges frames, it does not look at the timing of those frames.

Are the two animations in sync with the same time delays AND number of frames.

See the raw notes of the very last part of IM Examples Animation Modification page, where I note what needs to happen, though have not added an operator to IM to synchronize the times of an animation.

Re: Compose one animation over another

Posted: 2008-09-03T17:11:50-07:00
by StephenP
Thanks for the advice :)
I've had some success (finally) doing it manually in the command line, by coalescing then multiplying each image in so that each list has equal numbers of frames. Hopefully, I can figure out a more intelligent way of doing it, as I don't want much lag in my PHP implementation.

-Stephen

Re: Compose one animation over another

Posted: 2008-09-03T22:22:23-07:00
by anthony
Let us know what you come up with.