Page 1 of 1

Merge animated GIF and PNG with transparency

Posted: 2020-02-26T04:22:36-07:00
by DieterK
Hello,

I have an animated GIF (fire.gif) and I would now like to use ImageMagick to insert a PNG with transparency (product.png) in the middle of this GIF.

Example:
Animated GIF: fire.gif 600x600
PNG file with transparency: product.png 400x400

The PNG should be placed in the middle of the GIF (top layer) and slightly smaller (300x300)

I already tried it with convert (composite) and composite, unfortunately without success. In most attempts the GIF was not animated properly or did not work at all.

I would be very happy about tips and hints.

Thanks,
Dieter

Re: Merge animated GIF and PNG with transparency

Posted: 2020-02-26T04:36:45-07:00
by snibgo
What version of IM? On what platform? Please supply sample input files.

You want to composite a png over every frame of a gif. There are three stages:

1. Create frame images from the input gif: "-layers coalesce".

2. Compose the png over each of those frame images: "-layers composite".

3. Write the output gif.

Re: Merge animated GIF and PNG with transparency

Posted: 2020-02-26T07:36:35-07:00
by DieterK
Thanks,

so I have to split the GIF first into individual files, then edit the individual images and then create a new gif from them?

Or can I do that in one command?

Thanks

Re: Merge animated GIF and PNG with transparency

Posted: 2020-02-26T09:27:37-07:00
by snibgo
You have to create individual images that represent each entire frame, but you don't need to save these as files.

The command could be something like (IM v7, Windows BAT syntax):

Code: Select all

magick ^
  in.gif ^
  -layers coalesce ^
  null: ^
  in.png ^
  -gravity Center -layers composite ^
  out.gif