1CJPEG(1)                    General Commands Manual                   CJPEG(1)
2
3
4

NAME

6       cjpeg - compress an image file to a JPEG file
7

SYNOPSIS

9       cjpeg [ options ] [ filename ]
10

DESCRIPTION

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 grayscale format), BMP, Targa, and RLE (Utah Raster  Tool‐
16       kit format).  (RLE is supported only if the URT library is available.)
17

OPTIONS

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       -rgb   Create  RGB JPEG file.  Using this switch suppresses the conver‐
40              sion from RGB colorspace input to the default  YCbCr  JPEG  col‐
41              orspace.
42
43       -optimize
44              Perform  optimization  of  entropy encoding parameters.  Without
45              this, default encoding parameters are used.   -optimize  usually
46              makes  the  JPEG  file a little smaller, but cjpeg runs somewhat
47              slower and needs much more memory.  Image quality and  speed  of
48              decompression are unaffected by -optimize.
49
50       -progressive
51              Create progressive JPEG file (see below).
52
53       -targa Input  file is Targa format.  Targa files that contain an "iden‐
54              tification" field will not be automatically recognized by cjpeg;
55              for  such  files you must specify -targa to make cjpeg treat the
56              input as Targa format.  For most Targa  files,  you  won't  need
57              this switch.
58
59       The  -quality  switch  lets  you trade off compressed file size against
60       quality of the reconstructed image: the higher the quality setting, the
61       larger  the  JPEG  file, and the closer the output image will be to the
62       original input.  Normally you want to use the  lowest  quality  setting
63       (smallest  file)  that  decompresses  into something visually indistin‐
64       guishable from the original image.  For this purpose the  quality  set‐
65       ting should generally be between 50 and 95 (the default is 75) for pho‐
66       tographic images.  If you see defects at -quality 75, then go up  5  or
67       10  counts  at  a time until you are happy with the output image.  (The
68       optimal setting will vary from one image to another.)
69
70       -quality 100 will generate a quantization table of all 1's,  minimizing
71       loss  in  the quantization step (but there is still information loss in
72       subsampling, as well as roundoff error.)  For most images, specifying a
73       quality  value  above about 95 will increase the size of the compressed
74       file dramatically, and while the quality gain from these higher quality
75       values is measurable (using metrics such as PSNR or SSIM), it is rarely
76       perceivable by human vision.
77
78       In the other direction, quality values below 50 will produce very small
79       files of low image quality.  Settings around 5 to 10 might be useful in
80       preparing an index of a large image library, for example.  Try -quality
81       2 (or so) for some amusing Cubist effects.  (Note: quality values below
82       about 25 generate 2-byte  quantization  tables,  which  are  considered
83       optional  in the JPEG standard.  cjpeg emits a warning message when you
84       give such a quality value, because some  other  JPEG  programs  may  be
85       unable  to  decode  the  resulting  file.  Use -baseline if you need to
86       ensure compatibility at low quality values.)
87
88       The -quality option has been extended in this version of cjpeg to  sup‐
89       port  separate  quality  settings for luminance and chrominance (or, in
90       general, separate settings for every  quantization  table  slot.)   The
91       principle  is the same as chrominance subsampling:  since the human eye
92       is more sensitive to spatial changes in brightness than spatial changes
93       in  color,  the  chrominance  components can be quantized more than the
94       luminance components without incurring any visible image quality  loss.
95       However, unlike subsampling, this feature reduces data in the frequency
96       domain instead of the spatial  domain,  which  allows  for  more  fine-
97       grained  control.   This option is useful in quality-sensitive applica‐
98       tions, for which the artifacts generated by subsampling  may  be  unac‐
99       ceptable.
100
101       The -quality option accepts a comma-separated list of parameters, which
102       respectively refer to the quality levels that should be assigned to the
103       quantization table slots.  If there are more q-table slots than parame‐
104       ters, then the last parameter is replicated.  Thus, if only one quality
105       parameter  is  given,  this  is used for both luminance and chrominance
106       (slots 0 and 1, respectively), preserving the legacy behavior of  cjpeg
107       v6b  and  prior.   More  (or customized) quantization tables can be set
108       with the -qtables option and assigned to components  with  the  -qslots
109       option (see the "wizard" switches below.)
110
111       JPEG  files  generated  with separate luminance and chrominance quality
112       are fully compliant with standard JPEG decoders.
113
114       CAUTION: For this setting to be useful, be sure to pass an argument  of
115       -sample  1x1  to  cjpeg to disable chrominance subsampling.  Otherwise,
116       the default subsampling level (2x2, AKA "4:2:0") will be used.
117
118       The -progressive switch creates a "progressive  JPEG"  file.   In  this
119       type  of  JPEG file, the data is stored in multiple scans of increasing
120       quality.  If the file is being transmitted over a  slow  communications
121       link, the decoder can use the first scan to display a low-quality image
122       very quickly, and can then improve the  display  with  each  subsequent
123       scan.  The final image is exactly equivalent to a standard JPEG file of
124       the same quality setting, and the total file size is about the same ---
125       often a little smaller.
126
127       Switches for advanced users:
128
129       -arithmetic
130              Use  arithmetic  coding.   Caution: arithmetic coded JPEG is not
131              yet widely implemented, so many decoders will be unable to  view
132              an arithmetic coded JPEG file at all.
133
134       -dct int
135              Use integer DCT method (default).
136
137       -dct fast
138              Use  fast  integer  DCT  (less accurate).  In libjpeg-turbo, the
139              fast method is generally about 5-15% faster than the int  method
140              when using the x86/x86-64 SIMD extensions (results may vary with
141              other SIMD implementations, or when using libjpeg-turbo  without
142              SIMD  extensions.)   For  quality  levels of 90 and below, there
143              should be little or no perceptible difference  between  the  two
144              algorithms.   For  quality levels above 90, however, the differ‐
145              ence between the fast and the  int  methods  becomes  more  pro‐
146              nounced.   With quality=97, for instance, the fast method incurs
147              generally about a 1-3 dB loss (in  PSNR)  relative  to  the  int
148              method,  but this can be larger for some images.  Do not use the
149              fast method with quality levels above 97.  The  algorithm  often
150              degenerates  at  quality=98 and above and can actually produce a
151              more lossy image than if lower quality  levels  had  been  used.
152              Also, in libjpeg-turbo, the fast method is not fully accelerated
153              for quality levels above 97, so it will be slower than  the  int
154              method.
155
156       -dct float
157              Use  floating-point  DCT  method.   The float method is mainly a
158              legacy feature.  It does not produce significantly more accurate
159              results  than  the int method, and it is much slower.  The float
160              method may also give different results on different machines due
161              to varying roundoff behavior, whereas the integer methods should
162              give the same results on all machines.
163
164       -icc file
165              Embed ICC color management profile contained  in  the  specified
166              file.
167
168       -restart N
169              Emit  a  JPEG  restart  marker  every N MCU rows, or every N MCU
170              blocks if "B" is  attached  to  the  number.   -restart  0  (the
171              default) means no restart markers.
172
173       -smooth N
174              Smooth the input image to eliminate dithering noise.  N, ranging
175              from 1 to 100, indicates the  strength  of  smoothing.   0  (the
176              default) means no smoothing.
177
178       -maxmemory N
179              Set  limit  for  amount  of  memory  to  use in processing large
180              images.  Value is in thousands of bytes, or millions of bytes if
181              "M"  is  attached  to  the number.  For example, -max 4m selects
182              4000000 bytes.  If more space is needed, an error will occur.
183
184       -outfile name
185              Send output image to the named file, not to standard output.
186
187       -memdst
188              Compress to memory instead of a file.  This feature  was  imple‐
189              mented mainly as a way of testing the in-memory destination man‐
190              ager (jpeg_mem_dest()), but it is also useful for  benchmarking,
191              since it reduces the I/O overhead.
192
193       -verbose
194              Enable  debug printout.  More -v's give more output.  Also, ver‐
195              sion information is printed at startup.
196
197       -debug Same as -verbose.
198
199       -version
200              Print version information and exit.
201
202       The -restart option inserts extra markers that allow a JPEG decoder  to
203       resynchronize after a transmission error.  Without restart markers, any
204       damage to a compressed file will usually ruin the image from the  point
205       of  the error to the end of the image; with restart markers, the damage
206       is usually confined to the portion of the image up to the next  restart
207       marker.   Of course, the restart markers occupy extra space.  We recom‐
208       mend -restart 1 for images that will be transmitted  across  unreliable
209       networks such as Usenet.
210
211       The  -smooth  option  filters  the input to eliminate fine-scale noise.
212       This is often useful when converting dithered images to JPEG: a  moder‐
213       ate  smoothing factor of 10 to 50 gets rid of dithering patterns in the
214       input file, resulting in a  smaller  JPEG  file  and  a  better-looking
215       image.   Too large a smoothing factor will visibly blur the image, how‐
216       ever.
217
218       Switches for wizards:
219
220       -baseline
221              Force baseline-compatible quantization tables to  be  generated.
222              This  clamps  quantization  values to 8 bits even at low quality
223              settings.  (This switch is  poorly  named,  since  it  does  not
224              ensure  that the output is actually baseline JPEG.  For example,
225              you can use -baseline and -progressive together.)
226
227       -qtables file
228              Use the quantization tables given in the specified text file.
229
230       -qslots N[,...]
231              Select which quantization table to use for each color component.
232
233       -sample HxV[,...]
234              Set JPEG sampling factors for each color component.
235
236       -scans file
237              Use the scan script given in the specified text file.
238
239       The "wizard" switches are intended for experimentation with  JPEG.   If
240       you  don't know what you are doing, don't use them.  These switches are
241       documented further in the file wizard.txt.
242

EXAMPLES

244       This example compresses the PPM file foo.ppm with a quality  factor  of
245       60 and saves the output as foo.jpg:
246
247              cjpeg -quality 60 foo.ppm > foo.jpg
248

HINTS

250       Color  GIF  files  are  not  the  ideal  input for JPEG; JPEG is really
251       intended for compressing full-color (24-bit)  images.   In  particular,
252       don't  try  to  convert  cartoons, line drawings, and other images that
253       have only a few distinct colors.  GIF works great on these,  JPEG  does
254       not.   If you want to convert a GIF to JPEG, you should experiment with
255       cjpeg's -quality and -smooth options to get a satisfactory  conversion.
256       -smooth 10 or so is often helpful.
257
258       Avoid  running an image through a series of JPEG compression/decompres‐
259       sion cycles.  Image quality loss  will  accumulate;  after  ten  or  so
260       cycles  the  image may be noticeably worse than it was after one cycle.
261       It's best to use a lossless format while manipulating  an  image,  then
262       convert to JPEG format when you are ready to file the image away.
263
264       The  -optimize  option  to  cjpeg  is worth using when you are making a
265       "final" version for posting or archiving.  It's also a win when you are
266       using  low quality settings to make very small JPEG files; the percent‐
267       age improvement is often a lot more than it is on  larger  files.   (At
268       present,  -optimize mode is always selected when generating progressive
269       JPEG files.)
270

ENVIRONMENT

272       JPEGMEM
273              If this environment variable is set, its value  is  the  default
274              memory  limit.   The  value  is  specified  as described for the
275              -maxmemory switch.  JPEGMEM overrides the default  value  speci‐
276              fied  when the program was compiled, and itself is overridden by
277              an explicit -maxmemory.
278

SEE ALSO

280       djpeg(1), jpegtran(1), rdjpgcom(1), wrjpgcom(1)
281       ppm(5), pgm(5)
282       Wallace, Gregory K.  "The JPEG  Still  Picture  Compression  Standard",
283       Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
284

AUTHOR

286       Independent JPEG Group
287
288       This  file  was  modified  by The libjpeg-turbo Project to include only
289       information relevant to libjpeg-turbo, to wordsmith  certain  sections,
290       and to describe features not present in libjpeg.
291

ISSUES

293       Support  for  GIF  input files was removed in cjpeg v6b due to concerns
294       over the Unisys LZW patent.  Although  this  patent  expired  in  2006,
295       cjpeg  still lacks GIF support, for these historical reasons.  (Conver‐
296       sion of GIF files to JPEG is usually a bad idea anyway, since GIF is  a
297       256-color format.)
298
299       Not all variants of BMP and Targa file formats are supported.
300
301       The  -targa switch is not a bug, it's a feature.  (It would be a bug if
302       the Targa format designers had not been clueless.)
303
304
305
306                                 18 March 2017                        CJPEG(1)
Impressum