Encyclopedia > Wikipedia:How to reduce colors for saving a JPEG as PNG

  Article Content

Wikipedia:How to reduce colors for saving a JPEG as PNG

Sometimes, you find a drawing or similar image useful for a Wikipedia article, that was saved in the JPEG format while it should have been saved in the PNG format. For instance, a drawing of a flag, or a map.

Just automatically converting to PNG will almost never produce a good image. It is likely that the resulting file will be even larger than the original JPEG, and will maintain its poor quality.

But if you have a good bitmap graphic editing program with which you are reasonably skilled, you can produce a good result. This tutorial uses the GIMP, but it can be used with most bitmap graphics editors.

Some background about the formats

When you need to save an image with thousands of colors or more (as is typical in "photographic" images with fine gradations of shade and tone), your best bet is probably to save it as a JPEG file. JPEG's compression method takes advantage of the fact that most natural scenes have smooth gradients and soft edges, and so is optimized for that.

PNG, however, uses lossless compression, which means that it saves every pixel exactly as it was drawn, which is ideal for iconic images such as graphs, flags, maps, and cartoons. Its compression is optimized for images with large areas of identical color with sharp edges.

In addition, though, PNG format is very versatile. You can store images as PNG files while retaining more colors than the human eye can possibly distinguish, and can represent more colors and finer details than even JPEG, but only when saved in PNG's "true color" mode. However, when you save an image as a true color PNG, you tend to get overly large files, since its compression is not optimized for such images.

If you merely convert a JPEG to a PNG, your graphics program will likely produce one of these true color PNGs, and make a large file. You should convert such PNGs to "indexed" or "palette-based" mode before you upload them. Most bitmap graphics editors will let you convert from true color mode (also called "full color" or "RGB"), and to decide the number of colors you want in the resulting indexed image. How many colors you choose will depend upon the image--it must be fewer than 256, but often 16 or even fewer will work well. They may also ask if you want to use something called "error diffusion" or "dithering". You will probably want to turn this option off. Experiment until you get it a result you like. Some tools may let you count the actual number of different colors in a file.

Delete similar colors

Once an image such as a map has been saved as JPEG inadvertently, it often contains neighboring colors that look the same to the human eye, but which are in fact different. PNG's compression method needlessly preserves these differences, and the result will be that saving that image may not yield the reduction in file size that you hoped for. To remedy this, you can use the method described below to make sure that there are no more colors in the image than you actually need.

Making an image that was incorrectly saved as JPEG fit for saving as PNG
Suppose you have got a map for an island that was inadvertently saved as JPEG. Looks OK, if a bit fuzzy. 1. In your bitmap graphics editor, set your fuzzy selection ("magic wand") tool so that it only will select pixels of exactly the same color. (Here: Threshold = 0) 2. Click on the main land mass: see how it does not select every pixel of the land mass? This is the result of saving as JPEG, and usually hardly noticable to the human eye.
 
3. Go back to the fuzzy select tool, and make it less uptight. 4. As you can see, more of the land mass will be selected. Experiment to get all of the land, but none of the edge surrounding the island. You may have to manually clean up visible "speckles".

After you have the selection as shown above, choose an appropriate color for the land mass, and make sure the entire selected area is filled. How to do this may differ between applications. Once the image consists of the color of the sea, the color of the land and the intermediate colors of the edge between sea and land, you can reduce the number of colors to about sixteen and save as an indexed PNG. Again, experiment until you get it right.

The result of all of this effort is that you should get an image file that is smaller than the original image (and thus takes less download time) and which will be sharper and clearer (JPEG often leaves blurry edges and speckles in what should be smooth areas of color).

Of course, forcing your raster graphics editor to reduce the number of colors in this example to 16 may have the exact same result and take less time to do. This doesn't work, though, if there are visible defects from the JPEG process that you have to clean up first.

This article is here in the first place to make you aware that such tiny color differences exist, and show you how to deal with them. If you just count the number of colors in a JPEG and then base the number of PNG palette entries on this count, you will leave unnecessary information in the image.

Second, not all image editors will let you force the number of colors using the correct colors! And those that do often have a bewildering array of options to set before you get the right colors.

Related topics



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
Canadian Charter of Rights and Freedoms

... with Supplement to Constitutional Law of Canada (2002-) Humphrey, J.P., Human Rights and the United Nations: A Great Adventure (New York: Transnationa ...

 
 
 
This page was created in 37.4 ms