Page 1 of 1

How do I limit JPG to 256 colors?

Posted: 2010-05-26T16:06:34-07:00
by imagewinter
How do I limit JPG to 256 colors and not blend surrounding colors?

The same technique used by GIF.

If I were to compare a low quality picture of GIF and JPG, the GIF would be sharper and more clear because it does not blend surrounding colors together like JPG does. How can this be achived in JPG?

Re: How do I limit JPG to 256 colors?

Posted: 2010-05-26T16:51:03-07:00
by snibgo
I don't understand the question. Can you supply examples that illustrate it?

Jpeg is a lossy compression. It will introduce artifacts, which will change pixels.

Re: How do I limit JPG to 256 colors?

Posted: 2010-05-26T17:41:07-07:00
by fmw42
I don't think it can unless you use a non-lossy jpg compression such as in jpg2000 (jp2 format).

The best you can do is.

convert image.jpg -colors 256 +dither -depth 8 -quality 100 result.jpg


But the fact that the output is jpg, will cause it to be compressed and so mix colors so that you get more than 256 colors again.

Re: How do I limit JPG to 256 colors?

Posted: 2010-06-02T06:11:49-07:00
by Drarakel
Also, use "-sampling-factor 1x1" (alongside "-quality 100") for the best JPEG output. Subsampling can 'smear' some colors. Perhaps you meant that with "blend surrounding colors".