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, GIF, and Targa.
16

OPTIONS

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

EXAMPLES

259       This  example  compresses the PPM file foo.ppm with a quality factor of
260       60 and saves the output as foo.jpg:
261
262              cjpeg -quality 60 foo.ppm > foo.jpg
263

HINTS

265       Color GIF files are not the ideal input for JPEG; JPEG  is  really  in‐
266       tended  for  compressing  full-color  (24-bit)  images.  In particular,
267       don't try to convert cartoons, line drawings,  and  other  images  that
268       have  only  a few distinct colors.  GIF works great on these, JPEG does
269       not.  If you want to convert a GIF to JPEG, you should experiment  with
270       cjpeg's  -quality and -smooth options to get a satisfactory conversion.
271       -smooth 10 or so is often helpful.
272
273       Avoid running an image through a series of JPEG  compression/decompres‐
274       sion  cycles.   Image quality loss will accumulate; after ten or so cy‐
275       cles the image may be noticeably worse than it  was  after  one  cycle.
276       It's  best  to  use a lossless format while manipulating an image, then
277       convert to JPEG format when you are ready to file the image away.
278
279       The -optimize option to cjpeg is worth using when you are making a "fi‐
280       nal"  version  for  posting or archiving.  It's also a win when you are
281       using low quality settings to make very small JPEG files; the  percent‐
282       age  improvement  is  often a lot more than it is on larger files.  (At
283       present, -optimize mode is always selected when generating  progressive
284       JPEG files.)
285

ENVIRONMENT

287       JPEGMEM
288              If  this  environment  variable is set, its value is the default
289              memory limit.  The value  is  specified  as  described  for  the
290              -maxmemory  switch.   JPEGMEM overrides the default value speci‐
291              fied when the program was compiled, and itself is overridden  by
292              an explicit -maxmemory.
293

SEE ALSO

295       djpeg(1), jpegtran(1), rdjpgcom(1), wrjpgcom(1)
296       ppm(5), pgm(5)
297       Wallace,  Gregory  K.   "The  JPEG Still Picture Compression Standard",
298       Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
299

AUTHOR

301       Independent JPEG Group
302
303       This file was modified by The libjpeg-turbo Project to include only in‐
304       formation relevant to libjpeg-turbo, to wordsmith certain sections, and
305       to describe features not present in libjpeg.
306

ISSUES

308       Not all variants of BMP and Targa file formats are supported.
309
310       The -targa switch is not a bug, it's a feature.  (It would be a bug  if
311       the Targa format designers had not been clueless.)
312
313
314
315                               18 November 2021                       CJPEG(1)
Impressum