composite over gif

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
alealvaro
Posts: 7
Joined: 2016-08-18T19:43:26-07:00
Authentication code: 1151

composite over gif

Post by alealvaro »

Hello! Please I need help with this:

I have a gif image, and I need to composite over that Image a png. How can I do that?

I tried to composite right over the gif, like:

Code: Select all

composite -geometry +519+0 overlay.png my.gif test.gif
But only put the png in the first frame.

Then I tried:

Code: Select all

convert -coalesce my.gif out%05d.png
In order to have all the gif's frames separately, thinking I could try to put the png over each one and then generate the gif again, but I couldn't find how to do that :(

What do you think? Which would be the best approach and how can I handle it?

Thanks in advance!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: composite over gif

Post by fmw42 »

Please, always provide your IM version and platform when asking questions, since syntax may differ. Also provide your your images.

See viewtopic.php?f=1&t=9620

See the top-most post in this forum README FIRST at: -layers composite at http://www.imagemagick.org/Usage/anim_mods/

Example:

GIF Animation:
Image

PNG:
Image

Code: Select all

convert hue_rotation_animation.gif -coalesce null: cyclops.png -gravity center -layers composite result.gif
Image
alealvaro
Posts: 7
Joined: 2016-08-18T19:43:26-07:00
Authentication code: 1151

Re: composite over gif

Post by alealvaro »

Thanks for your answer.

This is the data:
Version: ImageMagick 6.7.2-7 2016-06-16 Q16 http://www.imagemagick.org (running on CentOS)
Animated gif: http://stream1.gifsoup.com/view1/473665 ... -3-a-o.gif
PNG overlay: http://koti.tamk.fi/~c2nsaijo/insurance ... c_link.png

I need to the PNG overlay over the animated gif, aligned to the right. Thanks in advance!
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: composite over gif

Post by GeeMack »

alealvaro wrote:I need to the PNG overlay over the animated gif, aligned to the right. Thanks in advance!
Something like this should work...

Code: Select all

convert bugatti-3-a-o.gif null: -gravity east sidepic_link.png -layers composite bugatti-new.gif
alealvaro
Posts: 7
Joined: 2016-08-18T19:43:26-07:00
Authentication code: 1151

Re: composite over gif

Post by alealvaro »

Thanks! That helped me to make it works!!

Just one more question, I tried with this images:

(you could find them in this Google drive folder) https://drive.google.com/drive/folders/ ... sp=sharing

There are a gif and a png, I tried to generate the new gif with this command:

Code: Select all

convert my_image.gif -geometry +519+0 -coalesce null: hotlist-overlay.png -layers composite result.gif
It worked! But if you check the result.gif in the same folder, some pixels are weird. Is there any chance to improve this cli and make the result gif better without those dots? Thanks again!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: composite over gif

Post by fmw42 »

I think you should specify -geometry and/or -gravity after the hotlist-overlay.png. So try either of these

Code: Select all

convert my_image.gif -coalesce null: hotlist-overlay.png -geometry +519+0 -layers composite result1.gif

Code: Select all

convert my_image.gif -coalesce null: hotlist-overlay.png -gravity east -layers composite result2.gif
alealvaro
Posts: 7
Joined: 2016-08-18T19:43:26-07:00
Authentication code: 1151

Re: composite over gif

Post by alealvaro »

You're right, that order for geometry and gravity are the right one, but, I'm still having those weird dots in the result image. Is there anything else I could try? Could be these some kind of problem with the amount of colors the gif has?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: composite over gif

Post by fmw42 »

I don't see any weird pixels. Can you explain further?

But if you combine a gif animation with the png, the color map changes for each frame due to the colors in the overlay image. So it is possible that some colors are slightly different. GIF only allows 256 colors per frame. For example if you had no red in the original animation, now you have to remove some color from the animation to make room for the red color of the png.
alealvaro
Posts: 7
Joined: 2016-08-18T19:43:26-07:00
Authentication code: 1151

Re: composite over gif

Post by alealvaro »

Thanks for the explanación!

I mean for example in the upper left cornet the sky in the post lose some quality. Or in the upper right córner, just before the overlay, the are some dancing píxels in the cortain. Those weird píxels are not in the original gif. Is there any way to avoid that?

Thanks again!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: composite over gif

Post by fmw42 »

Adding +dither to turn off dithering when regenerating the gif colortables seems to help mitigate it. I do not think you can avoid it due to the reason I gave about making room for other colors in the limited 256 color colortable.

Code: Select all

convert my_image.gif -coalesce null: hotlist-overlay.png -gravity east +dither -layers composite result3.gif
Post Reply