# When exporting an (animated) GIF, is it possible to specify the size of the color palette?

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?

-
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 optiview.com. 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"]
(*
114000
57095
*)

-
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