1 .TH JPEGTRAN 1 "13 July 2021"
3 jpegtran \- lossless transformation of JPEG files
16 performs various useful transformations of JPEG files.
17 It can translate the coded representation from one variant of JPEG to another,
18 for example from baseline JPEG to progressive JPEG or vice versa. It can also
19 perform some rearrangements of the image data, for example turning an image
20 from landscape to portrait format by rotation.
22 For EXIF files and JPEG files containing Exif data, you may prefer to use
27 works by rearranging the compressed data (DCT coefficients), without
28 ever fully decoding the image. Therefore, its transformations are lossless:
29 there is no image degradation at all, which would not be true if you used
33 to accomplish the same conversion. But by the same token,
35 cannot perform lossy operations such as changing the image quality. However,
36 while the image data is losslessly transformed, metadata can be removed. See
42 reads the named JPEG/JFIF file, or the standard input if no file is
43 named, and produces a JPEG/JFIF file on the standard output.
45 All switch names may be abbreviated; for example,
51 Upper and lower case are equivalent.
52 British spellings are also accepted (e.g.,
54 though for brevity these are not mentioned below.
56 To specify the coded JPEG representation used in the output file,
58 accepts a subset of the switches recognized by
62 Perform optimization of entropy encoding parameters.
65 Create progressive JPEG file.
68 Emit a JPEG restart marker every N MCU rows, or every N MCU blocks if "B" is
69 attached to the number.
72 Use arithmetic coding.
75 Use the scan script given in the specified text file.
79 for more details about these switches.
80 If you specify none of these switches, you get a plain baseline-JPEG output
81 file. The quality setting and so forth are determined by the input file.
83 The image can be losslessly transformed by giving one of these switches:
86 Mirror image horizontally (left-right).
89 Mirror image vertically (top-bottom).
92 Rotate image 90 degrees clockwise.
95 Rotate image 180 degrees.
98 Rotate image 270 degrees clockwise (or 90 ccw).
101 Transpose image (across UL-to-LR axis).
104 Transverse transpose (across UR-to-LL axis).
106 The transpose transformation has no restrictions regarding image dimensions.
107 The other transformations operate rather oddly if the image dimensions are not
108 a multiple of the iMCU size (usually 8 or 16 pixels), because they can only
109 transform complete blocks of DCT coefficient data in the desired way.
112 default behavior when transforming an odd-size image is designed
113 to preserve exact reversibility and mathematical consistency of the
114 transformation set. As stated, transpose is able to flip the entire image
115 area. Horizontal mirroring leaves any partial iMCU column at the right edge
116 untouched, but is able to flip all rows of the image. Similarly, vertical
117 mirroring leaves any partial iMCU row at the bottom edge untouched, but is
118 able to flip all columns. The other transforms can be built up as sequences
119 of transpose and flip operations; for consistency, their actions on edge
120 pixels are defined to be the same as the end result of the corresponding
121 transpose-and-flip sequence.
123 For practical use, you may prefer to discard any untransformable edge pixels
124 rather than having a strange-looking strip along the right and/or bottom edges
125 of a transformed image. To do this, add the
130 Drop non-transformable edge blocks.
132 Obviously, a transformation with
134 is not reversible, so strictly speaking
136 with this switch is not lossless. Also, the expected mathematical
137 equivalences between the transformations no longer hold. For example,
139 trims only the bottom edge, but
146 If you are only interested in perfect transformations, add the
150 to fail with an error if the transformation is not perfect.
152 For example, you may want to do
154 .B (jpegtran \-rot 90 -perfect
158 .B | pnmflip \-r90 | cjpeg)
160 to do a perfect rotation, if available, or an approximated one if not.
162 This version of \fBjpegtran\fR also offers a lossless crop option, which
163 discards data outside of a given image region but losslessly preserves what is
164 inside. Like the rotate and flip transforms, lossless crop is restricted by
165 the current JPEG format; the upper left corner of the selected region must fall
166 on an iMCU boundary. If it doesn't, then it is silently moved up and/or left
167 to the nearest iMCU boundary (the lower right corner is unchanged.) Thus, the
168 output image covers at least the requested region, but it may cover more. The
169 adjustment of the region dimensions may be optionally disabled by attaching an
170 'f' character ("force") to the width or height number.
172 The image can be losslessly cropped by giving the switch:
175 Crop the image to a rectangular region of width W and height H, starting at
176 point X,Y. The lossless crop feature discards data outside of a given image
177 region but losslessly preserves what is inside. Like the rotate and flip
178 transforms, lossless crop is restricted by the current JPEG format; the upper
179 left corner of the selected region must fall on an iMCU boundary. If it
180 doesn't, then it is silently moved up and/or left to the nearest iMCU boundary
181 (the lower right corner is unchanged.)
183 If W or H is larger than the width/height of the input image, then the output
184 image is expanded in size, and the expanded region is filled in with zeros
185 (neutral gray). Attaching an 'f' character ("flatten") to the width number
186 will cause each block in the expanded region to be filled in with the DC
187 coefficient of the nearest block in the input image rather than grayed out.
188 Attaching an 'r' character ("reflect") to the width number will cause the
189 expanded region to be filled in with repeated reflections of the input image
190 rather than grayed out.
192 A complementary lossless wipe option is provided to discard (gray out) data
193 inside a given image region while losslessly preserving what is outside:
196 Wipe (gray out) a rectangular region of width W and height H from the input
197 image, starting at point X,Y.
199 Attaching an 'f' character ("flatten") to the width number will cause the
200 region to be filled with the average of adjacent blocks rather than grayed out.
201 If the wipe region and the region outside the wipe region, when adjusted to the
202 nearest iMCU boundary, form two horizontally adjacent rectangles, then
203 attaching an 'r' character ("reflect") to the width number will cause the wipe
204 region to be filled with repeated reflections of the outside region rather than
207 A lossless drop option is also provided, which allows another JPEG image to be
208 inserted ("dropped") into the input image data at a given position, replacing
209 the existing image data at that position:
211 .B \-drop +X+Y filename
212 Drop (insert) another image at point X,Y
214 Both the input image and the drop image must have the same subsampling level.
215 It is best if they also have the same quantization (quality.) Otherwise, the
216 quantization of the output image will be adapted to accommodate the higher of
217 the input image quality and the drop image quality. The trim option can be
218 used with the drop option to requantize the drop image to match the input
219 image. Note that a grayscale image can be dropped into a full-color image or
220 vice versa, as long as the full-color image has no vertical subsampling. If
221 the input image is grayscale and the drop image is full-color, then the
222 chrominance channels from the drop image will be discarded.
224 Other not-strictly-lossless transformation switches are:
227 Force grayscale output.
229 This option discards the chrominance channels if the input image is YCbCr
230 (ie, a standard color JPEG), resulting in a grayscale JPEG file. The
231 luminance channel is preserved exactly, so this is a better method of reducing
232 to grayscale than decompression, conversion, and recompression. This switch
233 is particularly handy for fixing a monochrome picture that was mistakenly
234 encoded as a color JPEG. (In such a case, the space savings from getting rid
235 of the near-empty chroma channels won't be large; but the decoding time for
236 a grayscale JPEG is substantially less than that for a color JPEG.)
239 also recognizes these switches that control what to do with "extra" markers,
240 such as comment blocks:
243 Copy no extra markers from source file. This setting suppresses all
244 comments and other metadata in the source file.
247 Copy only comment markers. This setting copies comments from the source file
248 but discards any other metadata.
251 Copy only ICC profile markers. This setting copies the ICC profile from the
252 source file but discards any other metadata.
255 Copy all extra markers. This setting preserves miscellaneous markers
256 found in the source file, such as JFIF thumbnails, Exif data, and Photoshop
257 settings. In some files, these extra markers can be sizable. Note that this
258 option will copy thumbnails as-is; they will not be transformed.
260 The default behavior is \fB-copy comments\fR. (Note: in IJG releases v6 and
261 v6a, \fBjpegtran\fR always did the equivalent of \fB-copy none\fR.)
263 Additional switches recognized by jpegtran are:
266 Embed ICC color management profile contained in the specified file. Note that
267 this will cause \fBjpegtran\fR to ignore any APP2 markers in the input file,
268 even if \fB-copy all\fR or \fB-copy icc\fR is specified.
271 Set limit for amount of memory to use in processing large images. Value is
272 in thousands of bytes, or millions of bytes if "M" is attached to the
275 selects 4000000 bytes. If more space is needed, an error will occur.
278 Abort if the input image contains more than
280 scans. This feature demonstrates a method by which applications can guard
281 against denial-of-service attacks instigated by specially-crafted malformed
282 JPEG images containing numerous scans with missing image data or image data
283 consisting only of "EOB runs" (a feature of progressive JPEG images that allows
284 potentially hundreds of thousands of adjoining zero-value pixels to be
285 represented using only a few bytes.) Attempting to transform such malformed
286 JPEG images can cause excessive CPU activity, since the decompressor must fully
287 process each scan (even if the scan is corrupt) before it can proceed to the
290 .BI \-outfile " name"
291 Send output image to the named file, not to standard output.
294 Report transformation progress.
297 Treat all warnings as fatal. This feature also demonstrates a method by which
298 applications can guard against attacks instigated by specially-crafted
299 malformed JPEG images. Enabling this option will cause the decompressor to
300 abort if the input image contains incomplete or corrupt image data.
303 Enable debug printout. More
305 give more output. Also, version information is printed at startup.
312 Print version information and exit.
315 This example converts a baseline JPEG file to progressive form:
317 .B jpegtran \-progressive
322 This example rotates an image 90 degrees clockwise, discarding any
323 unrotatable edge pixels:
325 .B jpegtran \-rot 90 -trim
332 If this environment variable is set, its value is the default memory limit.
333 The value is specified as described for the
337 overrides the default value specified when the program was compiled, and
338 itself is overridden by an explicit
346 Wallace, Gregory K. "The JPEG Still Picture Compression Standard",
347 Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
349 Independent JPEG Group
351 This file was modified by The libjpeg-turbo Project to include only information
352 relevant to libjpeg-turbo and to wordsmith certain sections.
354 The transform options can't transform odd-size images perfectly. Use
358 if you don't like the results.
360 The entire image is read into memory and then written out again, even in
361 cases where this isn't really necessary. Expect swapping on large images,
362 especially when using the more complex transform options.