2

I am trying to merge a png with a gif (put the png on top of the gif) and then have the result as a gif.

I played around with convert, but cannot quite get it to work the way I need it.

I have tried these commands so far:

convert layer1.png layer2.gif -append mergedLayers.gif
convert-im6.q16: memory allocation failed `layer2.gif' @ error/gif.c/ReadGIFImage/1303.

Anybody got an idea?

Greenonline
  • 1,759
  • 7
  • 16
  • 21
milehigh
  • 23
  • 2
  • what are the contents of `identify -list policy | more` . it should return a policy file, please add it's contents in your initial answer – Alex Jan 18 '22 at 18:30

1 Answers1

2

You can do this using ffmpeg:

ffmpeg -y -i layer2.gif -i layer1.png -filter_complex [0]overlay=x=0:y=0[out] -map [out] -map 0:a? mergedLayers.gif

-y flag says to overwrite output files without asking. So if you already have a file named mergedLayers.gif it will get overwritten when this command is run.

-i flag is the input url (in this case just a file name). So you are passing two input files. layer2.gif and layer1.png.

-filter_complex flag in a sense is the function that is done on the inputs to make the output. In this case the function is [0]overlay=x=0:y=0[out]. The [0] indicates that you want to use the first input file as the object that is being overlayed on. If you were to use [1] instead of [0] you would end up with the png as the bottom layer. overlay=x=0:y=0 tells where to place the overlayed object. You can adjust where the png appears on the image by changing the x and y values in [0]overlay=x=0:y=0[out]. x=0:y=0 is the top left of the image. Increasing the value for x will move the image to the right. Increasing the value for y will move the image down. If =x=0:y=0 is omitted, overlay defaults to x=0:y=0.

-map flag is a way to designate an input as a source for the output. Probably unnecessary in such a simple case and you could just do:

ffmpeg -y -i layer2.gif -i layer1.png -filter_complex [0]overlay=x=0:y=0 mergedLayers.gif

Natolio
  • 1,137
  • 2
  • 12