cjpeg and djpeg

I far prefer to work with JPEG as a standard image format. It is not an illogical step to store master images as JPEGs (quality 95), as long as they remain unchanged. An alternative is PNG, but if the purpose of images is to be used as JPEGs, then storage of master files as high-quality JPEGs makes the world simple.

The only tools you need are a JPEG image, from anywhere, somewhere to store it, and cjpeg and djpeg to modify the image.

Here is how to compile and install the programs.

  1. ftp://ftp.uu.net/graphics/jpeg/ The latest version is jpegsrc.v6b.tar.gz.
  2. expand the tarball.
  3. issue these commands
% ./configure
% make
# make install

# requires root privileges.

I advise the following (my personal preferences are highlighted):

JPEG Compression Quality (for photos only)
ThumbnailsGeneral UseMasters
25-50% 50-75% 75-95%

It often helps to smooth very sharp pictures, e.g., -smooth 10 (looks better, smaller size). For doing more than this, try the Netpbm software and the GIMP. Of course, JPEG is not an image format designed for miscellaneous graphics--for that, use PNG.


Worries about data loss.

A jpeg isn't intended to contain the exact computer bits which were within the original image, but rather to contain the identical look. The accuracy of this "look" to the original may vary from perfectly indiscernable to practically indiscernable to utterly obvious.

The general rule for jpegs is that to uncompress an image, and then recompress it, results in a slightly degraded quality. Each link is slightly weaker than the last, and so a long chain (recompressing from the data in the previous compressed link) might spoil an image considerably. However, this does not turn out to be the case if the compression quality Q remains the same in every case. In fact, when retaining the same Q value, repeated use of JPEG compression did not lose any data whatsoever after the second such compression, even after 1,000 repetitions.

However, as the following two pictures illustrate, compressing over and over with different values of Q results in a continual loss of image information. A higher quality preserves a lower quality image accurately at the price of larger size, while a lower quality image loses part of the quality because it does not know exactly which part of the high quality represents the earlier low-quality image.

original Q = 75
image: jpeg 1
after 10 repetitions, with Q ranging from 66 to 75
image: jpeg 10
after 100 repetitions
image: jpeg 100

Note well: The image does not begin to lose useful information until the image compression quality begins to cycle.

Here is another image. Some don't survive as well.

original Q = 95 (somewhat blurred because of scaling--see note at the end)
image: abby 1
after 10 repetitions, with Q ranging from 86 to 95 (here it is interesting to note the sharpening effect)
image: abby 10
after 100 repetitions
image: abby 100

Same thing, but quality from 25 to 34.

Q = 25
image: cup 1
after 10 repetitions
image: cup 10
after 100 repetitions
image: cup 100

In general, it is safe to use an unscaled JPEG image as your master copy, for photographs only. Ensure that nothing happens to the file between scanning and saving as a high-quality JPEG (Q >= 95). This master will retain all usable picture information, while eliminating most of the expense of large files.