defaults for gif creation

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Mengu
Posts: 2
Joined: 2018-02-14T05:30:20-07:00
Authentication code: 1152
Location: Dersaadet
Contact:

defaults for gif creation

Post 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.
Mengu
Posts: 2
Joined: 2018-02-14T05:30:20-07:00
Authentication code: 1152
Location: Dersaadet
Contact:

Re: defaults for gif creation

Post by Mengu »

hi all

just wanted to bump this.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: defaults for gif creation

Post 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.
Post Reply