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)?


closed as off-topic by Alexey Popkov, b.gates.you.know.what, bbgodfrey, Öskå, JimB Dec 7 '18 at 6:05

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Alexey Popkov, b.gates.you.know.what, bbgodfrey, Öskå, JimB
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ What does ColorQuantize[Rasterize[Plot[Sin[x], {x, 0, 1}]], 16] produce for you? $\endgroup$ – J. M. is away 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. is away 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


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