# How to control image resolution in ColorQuantize? [closed]

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}]]


gives

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

• What does ColorQuantize[Rasterize[Plot[Sin[x], {x, 0, 1}]], 16] produce for you? – J. M.'s technical difficulties Apr 8 '18 at 2:27
• @J.M. Oh, good! Thank you very much! I can set ImageResolution inside Rasterize – matheorem Apr 8 '18 at 2:31
• 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. – J. M.'s technical difficulties Apr 8 '18 at 2:36
• @J.M.needshelp. I see. Thank you : ) – 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}];


Compare

ColorQuantize[plt, 16]


with

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