1CJPEG(1) General Commands Manual CJPEG(1)
2
3
4
6 cjpeg - compress an image file to a JPEG file
7
9 cjpeg [ options ] [ filename ]
10
12 cjpeg compresses the named image file, or the standard input if no file
13 is named, and produces a JPEG/JFIF file on the standard output. The
14 currently supported input file formats are: PPM (PBMPLUS color format),
15 PGM (PBMPLUS gray-scale format), BMP, Targa, and RLE (Utah Raster Tool‐
16 kit format). (RLE is supported only if the URT library is available.)
17
19 All switch names may be abbreviated; for example, -grayscale may be
20 written -gray or -gr. Most of the "basic" switches can be abbreviated
21 to as little as one letter. Upper and lower case are equivalent (thus
22 -BMP is the same as -bmp). British spellings are also accepted (e.g.,
23 -greyscale), though for brevity these are not mentioned below.
24
25 The basic switches are:
26
27 -quality N
28 Scale quantization tables to adjust image quality. Quality is 0
29 (worst) to 100 (best); default is 75. (See below for more
30 info.)
31
32 -grayscale
33 Create monochrome JPEG file from color input. Be sure to use
34 this switch when compressing a grayscale BMP file, because cjpeg
35 isn't bright enough to notice whether a BMP file uses only
36 shades of gray. By saying -grayscale, you'll get a smaller JPEG
37 file that takes less time to process.
38
39 -optimize
40 Perform optimization of entropy encoding parameters. Without
41 this, default encoding parameters are used. -optimize usually
42 makes the JPEG file a little smaller, but cjpeg runs somewhat
43 slower and needs much more memory. Image quality and speed of
44 decompression are unaffected by -optimize.
45
46 -progressive
47 Create progressive JPEG file (see below).
48
49 -targa Input file is Targa format. Targa files that contain an "iden‐
50 tification" field will not be automatically recognized by cjpeg;
51 for such files you must specify -targa to make cjpeg treat the
52 input as Targa format. For most Targa files, you won't need
53 this switch.
54
55 The -quality switch lets you trade off compressed file size against
56 quality of the reconstructed image: the higher the quality setting, the
57 larger the JPEG file, and the closer the output image will be to the
58 original input. Normally you want to use the lowest quality setting
59 (smallest file) that decompresses into something visually indistin‐
60 guishable from the original image. For this purpose the quality set‐
61 ting should be between 50 and 95; the default of 75 is often about
62 right. If you see defects at -quality 75, then go up 5 or 10 counts at
63 a time until you are happy with the output image. (The optimal setting
64 will vary from one image to another.)
65
66 -quality 100 will generate a quantization table of all 1's, minimizing
67 loss in the quantization step (but there is still information loss in
68 subsampling, as well as roundoff error). This setting is mainly of
69 interest for experimental purposes. Quality values above about 95 are
70 not recommended for normal use; the compressed file size goes up dra‐
71 matically for hardly any gain in output image quality.
72
73 In the other direction, quality values below 50 will produce very small
74 files of low image quality. Settings around 5 to 10 might be useful in
75 preparing an index of a large image library, for example. Try -quality
76 2 (or so) for some amusing Cubist effects. (Note: quality values below
77 about 25 generate 2-byte quantization tables, which are considered
78 optional in the JPEG standard. cjpeg emits a warning message when you
79 give such a quality value, because some other JPEG programs may be
80 unable to decode the resulting file. Use -baseline if you need to
81 ensure compatibility at low quality values.)
82
83 The -progressive switch creates a "progressive JPEG" file. In this
84 type of JPEG file, the data is stored in multiple scans of increasing
85 quality. If the file is being transmitted over a slow communications
86 link, the decoder can use the first scan to display a low-quality image
87 very quickly, and can then improve the display with each subsequent
88 scan. The final image is exactly equivalent to a standard JPEG file of
89 the same quality setting, and the total file size is about the same ---
90 often a little smaller. Caution: progressive JPEG is not yet widely
91 implemented, so many decoders will be unable to view a progressive JPEG
92 file at all.
93
94 Switches for advanced users:
95
96 -dct int
97 Use integer DCT method (default).
98
99 -dct fast
100 Use fast integer DCT (less accurate).
101
102 -dct float
103 Use floating-point DCT method. The float method is very
104 slightly more accurate than the int method, but is much slower
105 unless your machine has very fast floating-point hardware. Also
106 note that results of the floating-point method may vary slightly
107 across machines, while the integer methods should give the same
108 results everywhere. The fast integer method is much less accu‐
109 rate than the other two.
110
111 -restart N
112 Emit a JPEG restart marker every N MCU rows, or every N MCU
113 blocks if "B" is attached to the number. -restart 0 (the
114 default) means no restart markers.
115
116 -smooth N
117 Smooth the input image to eliminate dithering noise. N, ranging
118 from 1 to 100, indicates the strength of smoothing. 0 (the
119 default) means no smoothing.
120
121 -maxmemory N
122 Set limit for amount of memory to use in processing large
123 images. Value is in thousands of bytes, or millions of bytes if
124 "M" is attached to the number. For example, -max 4m selects
125 4000000 bytes. If more space is needed, temporary files will be
126 used.
127
128 -outfile name
129 Send output image to the named file, not to standard output.
130
131 -verbose
132 Enable debug printout. More -v's give more output. Also, ver‐
133 sion information is printed at startup.
134
135 -debug Same as -verbose.
136
137 The -restart option inserts extra markers that allow a JPEG decoder to
138 resynchronize after a transmission error. Without restart markers, any
139 damage to a compressed file will usually ruin the image from the point
140 of the error to the end of the image; with restart markers, the damage
141 is usually confined to the portion of the image up to the next restart
142 marker. Of course, the restart markers occupy extra space. We recom‐
143 mend -restart 1 for images that will be transmitted across unreliable
144 networks such as Usenet.
145
146 The -smooth option filters the input to eliminate fine-scale noise.
147 This is often useful when converting dithered images to JPEG: a moder‐
148 ate smoothing factor of 10 to 50 gets rid of dithering patterns in the
149 input file, resulting in a smaller JPEG file and a better-looking
150 image. Too large a smoothing factor will visibly blur the image, how‐
151 ever.
152
153 Switches for wizards:
154
155 -baseline
156 Force baseline-compatible quantization tables to be generated.
157 This clamps quantization values to 8 bits even at low quality
158 settings. (This switch is poorly named, since it does not
159 ensure that the output is actually baseline JPEG. For example,
160 you can use -baseline and -progressive together.)
161
162 -qtables file
163 Use the quantization tables given in the specified text file.
164
165 -qslots N[,...]
166 Select which quantization table to use for each color component.
167
168 -sample HxV[,...]
169 Set JPEG sampling factors for each color component.
170
171 -scans file
172 Use the scan script given in the specified text file.
173
174 The "wizard" switches are intended for experimentation with JPEG. If
175 you don't know what you are doing, don't use them. These switches are
176 documented further in the file wizard.doc.
177
179 This example compresses the PPM file foo.ppm with a quality factor of
180 60 and saves the output as foo.jpg:
181
182 cjpeg -quality 60 foo.ppm > foo.jpg
183
185 Color GIF files are not the ideal input for JPEG; JPEG is really
186 intended for compressing full-color (24-bit) images. In particular,
187 don't try to convert cartoons, line drawings, and other images that
188 have only a few distinct colors. GIF works great on these, JPEG does
189 not. If you want to convert a GIF to JPEG, you should experiment with
190 cjpeg's -quality and -smooth options to get a satisfactory conversion.
191 -smooth 10 or so is often helpful.
192
193 Avoid running an image through a series of JPEG compression/decompres‐
194 sion cycles. Image quality loss will accumulate; after ten or so
195 cycles the image may be noticeably worse than it was after one cycle.
196 It's best to use a lossless format while manipulating an image, then
197 convert to JPEG format when you are ready to file the image away.
198
199 The -optimize option to cjpeg is worth using when you are making a
200 "final" version for posting or archiving. It's also a win when you are
201 using low quality settings to make very small JPEG files; the percent‐
202 age improvement is often a lot more than it is on larger files. (At
203 present, -optimize mode is always selected when generating progressive
204 JPEG files.)
205
207 JPEGMEM
208 If this environment variable is set, its value is the default
209 memory limit. The value is specified as described for the
210 -maxmemory switch. JPEGMEM overrides the default value speci‐
211 fied when the program was compiled, and itself is overridden by
212 an explicit -maxmemory.
213
215 djpeg(1), jpegtran(1), rdjpgcom(1), wrjpgcom(1)
216 ppm(5), pgm(5)
217 Wallace, Gregory K. "The JPEG Still Picture Compression Standard",
218 Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
219
221 Independent JPEG Group
222
224 Arithmetic coding is not supported for legal reasons.
225
226 GIF input files are no longer supported, to avoid the Unisys LZW
227 patent. Use a Unisys-licensed program if you need to read a GIF file.
228 (Conversion of GIF files to JPEG is usually a bad idea anyway.)
229
230 Not all variants of BMP and Targa file formats are supported.
231
232 The -targa switch is not a bug, it's a feature. (It would be a bug if
233 the Targa format designers had not been clueless.)
234
235 Still not as fast as we'd like.
236
237
238
239 20 March 1998 CJPEG(1)