How do I limit JPG to 256 colors?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
imagewinter
Posts: 15
Joined: 2008-02-20T16:03:49-07:00

How do I limit JPG to 256 colors?

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How do I limit JPG to 256 colors?

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How do I limit JPG to 256 colors?

Post 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.
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: How do I limit JPG to 256 colors?

Post 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".
Post Reply