Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've exported an animation to animated GIF, which generated a 15mb file. I've been asked if I could regenerate the file, limiting it to only 16 colors, but I can't find any documentation on how I might do that. Is there a way to make Export[] reduce the color palette, preferably dithering as needed?

share|improve this question
Export[] in old versions of Mathematica supported a "ColorReductionPalette" option for exporting GIFs; it seems they have either removed or hidden this functionality. As for dithering, it seems Floyd-Steinberg dithering is already performed by default when exporting GIFs. – J. M. Jun 8 '12 at 9:48
You can always post-process your image using gifsicle or Nconvert or All of which are cross platform alternatives. Since the first two are command-line tools, you can also automate that process from MMA if necessary. – Ajasja Jun 8 '12 at 11:35
You could try something like Export["image.gif", ColorQuantize[#, 16] & /@ imglist]. – Heike Jun 8 '12 at 14:47
Using gifsicle as @Ajasja suggested, one can get roughly 30% smaller files while keeping all 256 colors. The command that I used to test this is gifsicle --colors=256 --optimize=2 < in.gif > out.gif – Jens Jun 9 '12 at 5:13
@jens great tip; gifsicle --optimize=3 --colors=16 < enormous.gif > smaller.gif produces a file half the size of the original 15 megabyte animated GIF file in question. The source animation uses very few colors anyway so 16 colors seems sufficient to my eye... – Jeff Atwood Jun 9 '12 at 11:44

Just too long for a comment. Here you can see the savings obtained by using the method explained in Heike's comment above:

i := ArrayPlot[RandomReal[1, {100, 200}], ColorFunction -> Hue];
StringLength@ExportString[k = {i, i}, "GIF"]
StringLength@ExportString[ColorQuantize[#, 16] & /@ k, "GIF"]
share|improve this answer
Here's how to verify that only sixteen colors were used: ExportString[ColorQuantize[test, 16], "GIF"]; Length[ImportString[%, "ColorMap"]] – J. M. Jun 9 '12 at 9:34
@J.M. Not sure, but perhaps one should check the "GlobalColorMap" too – Dr. belisarius Jun 9 '12 at 21:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.