When exporting a GIF animation, for example

listofgraphics = Table[Plot[Sin[x + a], {x, 0, 6}], {a, 0, 10, 1}];
Export["mtest.gif", listofgraphics, ImageResolution -> 200]

to make the GIF file size smaller, we can reduce the number of colors first, maybe by using ColorQuantize. But I found that using ColorQuantize directly reduces image resolution, e.g.

ColorQuantize[#, 16] &[Plot[Sin[x], {x, 0, 1}]]


rough image

The image is quite rough.

So is it possible to control image resolution in ColorQuantize, or is there any better way to reduce color when exporting to GIF (the docs seem to not give an option to reduce color in Export)?

  • $\begingroup$ What does ColorQuantize[Rasterize[Plot[Sin[x], {x, 0, 1}]], 16] produce for you? $\endgroup$ – J. M.'s technical difficulties Apr 8 '18 at 2:27
  • $\begingroup$ @J.M. Oh, good! Thank you very much! I can set ImageResolution inside Rasterize $\endgroup$ – matheorem Apr 8 '18 at 2:31
  • $\begingroup$ You need to remember that ColorQuantize[] expects an image as an argument, so if you feed it something that isn't an image, some conversions that may not be to your liking are done. $\endgroup$ – J. M.'s technical difficulties Apr 8 '18 at 2:36
  • $\begingroup$ @J.M.needshelp. I see. Thank you : ) $\endgroup$ – matheorem Apr 8 '18 at 2:42

To settle this:

As noted in the comments, the right way to go about this is to preprocess the plot first with Rasterize[], before passing it to ColorQuantize[]. Witness the following:

plt = Plot[Sin[x], {x, 0, π/2}];


ColorQuantize[plt, 16]

without rasterization


ColorQuantize[Rasterize[plt, "Image"], 16]

with rasterization

| improve this answer | |

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