in.gif (814KB)


in.jpg (1.03MB)


Commands i used to generate a gif -

convert -coalesce "in.gif" "0.png"

for file in 0*.png
  composite -gravity center "$file"   in.jpg   compose_over"$file"

convert compose_over*.png output.gif

output.gif (58.5MB)


The output GIF is not a smooth GIF like the original one. Why? And how can i make it a smooth GIF and how i reduce it's size?

1 Answer 1


Filenames end up as 0-0.png, 0-1.png, ..., 0-9.png, 0-10.png, 0-11.png, ...

But with * alphabetical expansion the order you're using them in ends up being 0-0.png, 0-1.png, 0-10.png, 0-11.png, ..., 0-19.png, 0-2.png, 0-21.png, ...

So you are processing frames out of order, resulting in the erratic animation.

To work around this issue you could use 0-?.png 0-??.png instead of 0*.png, or write it as 0-{0..35}.png (if there are 36 frames in total as in this example).

Or in the first command use "0%06d.png" as output filename so numbers will have leading zeroes to make alphabetical and numerical order identical.

Other issues are the loss of original gif animation speed / delays (in this case it seems to be -delay 4), and complete lack of GIF optimization (-layers Optimize) for smaller file size.

What ImageMagick gives me with those options added is a smooth 1.9MB file albeit with some graphical artifacts, IM's GIF optimizer seems to have some issues there. Using -layers OptimizePlus works for me but results in a somewhat larger file. You can try your luck with other software to optimize the GIF animation size.

For a better visual result you'd have to drop the GIF format entirely. It's simply not meant to incorporate photographic backgrounds. If you intend to use this on some webpage you could perhaps achieve the same effect with CSS, leaving the input files intact.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .