Page 1 of 1

defaults for gif creation

Posted: 2018-02-15T02:27:51-07:00
by Mengu
hi all

i'm using imagemagick with C++. i have couple of questions regarding gif creation. i create a gif like the following code:

Code: Select all

std::vector<Magick::Image> frames;

for (int i = 0; i < fromImages.size(); ++i) {
    Magick::Image img = fromImages[i].getImage();
    img.animationDelay(10);
    img.compressType(Magick::LZWCompression);
    frames.push_back(img);
}

Magick::writeImages(frames.begin(), frames.end(), outPath);
i have 16 images (each 640x640), the resulting gif is 4.5 mb. i also created a gif from the command line with `convert *.jpg -delay 1 result.gif`. file size is still 4.5 mb but quality is better. the following are my questions:

* what are the defaults for creating gif from the command line so i can apply them to my c++ code?
* how can i reduce file size but maintain quality?
* is setting -colors to 128 enough to make the gif in 128 colors?
* how can i reduce the noise in created gifs?

thanks in advance.

Re: defaults for gif creation

Posted: 2018-02-16T11:15:35-07:00
by Mengu
hi all

just wanted to bump this.

Re: defaults for gif creation

Posted: 2018-02-16T12:09:17-07:00
by fmw42
See
https://www.imagemagick.org/Usage/anim_opt/
https://www.imagemagick.org/Usage/anim_basics/

To reduce file size use -layers optimize. Also use the same color table for all frames via -remap. See https://www.imagemagick.org/Usage/quantize/#remap

+dither -colors 128 will ensure you have no more than 128 colors, but it could be less.

You will have to explain further about noise. But I suspect the use of -remap will help. That way, you do not get different sets of the same number of colors for each frame.