-->

imagemagick leaves artifacts in gif to jpg list co

2020-07-23 05:05发布

问题:

ImageMagick splits the gif into jpgs but some of them have white pixels and others do not.

convert -strip tree.gif tree.jpg

Splits the gif into 86 jpgs. Here are #68 and #69.

#68

and #69

and the gif in question:

about 1/3 have a similar encoding issue.

convert -version
Version: ImageMagick 6.6.9-7 2012-08-17 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP   

uname -a
Linux paul-Pangolin-Performance 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

回答1:

In animated GIF images, each new frame is drawn on top of the previous one, which means any pixels that are identical to the previous frame can be represented by transparent pixels. (Actually, this is only true for "Dispose None" animations, but that's what you have here. See here for details on the three kinds of disposal methods.)

Animated GIF optimizer tools take advantage of this, by looking for long runs of pixels that can be converted to transparent (so they can then be compressed more efficiently). So, that's why you probably have transparent pixels in the original image.

When those frames are converted to JPG, the transparent pixels are being converted to the background color, white.

See here for a description of how to fix it—you first want to convert your "Overlay Animation" into a "Coalesced Animation", and then you can convert that to a series of JPG files. It should look something like this:

convert tree.gif -coalesce -set dispose previous tree2.gif

Then verify that the animation looks identical, and then:

convert -strip tree2.gif tree.jpg

I haven't looked at the gif_anim_montage script linked from there that generated all the nice frame-by-frame images. I'm guessing it'll be doing effectively the same thing (plus more stuff), but maybe it has some neat tricks that will help you out, so I'd take a look.

PS, are you sure you want JPG output instead of, say, PNG, or even GIF? JPG is guaranteed to lose quality, while PNG is guaranteed not to. And, given the source data (256-color GIF images), PNG is likely to compress at least as well, or even better. A quick test shows it's 1980K vs. 1916K with the default settings, and with some trivial optimizing the PNGs come down to 1888K.