blob: da7a266974322d17a1dadc9cda57e47fe1cc9b33 [file] [log] [blame]
Jonathan Wrightbbb82822020-11-25 13:36:43 +00001.TH JPEGTRAN 1 "26 October 2020"
Tom Hudson0d47d2d2016-05-04 13:22:56 -04002.SH NAME
3jpegtran \- lossless transformation of JPEG files
4.SH SYNOPSIS
5.B jpegtran
6[
7.I options
8]
9[
10.I filename
11]
12.LP
13.SH DESCRIPTION
14.LP
15.B jpegtran
16performs various useful transformations of JPEG files.
17It can translate the coded representation from one variant of JPEG to another,
18for example from baseline JPEG to progressive JPEG or vice versa. It can also
19perform some rearrangements of the image data, for example turning an image
20from landscape to portrait format by rotation.
21.PP
22For EXIF files and JPEG files containing Exif data, you may prefer to use
23.B exiftran
24instead.
25.PP
26.B jpegtran
27works by rearranging the compressed data (DCT coefficients), without
28ever fully decoding the image. Therefore, its transformations are lossless:
29there is no image degradation at all, which would not be true if you used
30.B djpeg
31followed by
32.B cjpeg
33to accomplish the same conversion. But by the same token,
34.B jpegtran
35cannot perform lossy operations such as changing the image quality. However,
36while the image data is losslessly transformed, metadata can be removed. See
37the
38.B \-copy
39option for specifics.
40.PP
41.B jpegtran
42reads the named JPEG/JFIF file, or the standard input if no file is
43named, and produces a JPEG/JFIF file on the standard output.
44.SH OPTIONS
45All switch names may be abbreviated; for example,
46.B \-optimize
47may be written
48.B \-opt
49or
50.BR \-o .
51Upper and lower case are equivalent.
52British spellings are also accepted (e.g.,
53.BR \-optimise ),
54though for brevity these are not mentioned below.
55.PP
56To specify the coded JPEG representation used in the output file,
57.B jpegtran
58accepts a subset of the switches recognized by
59.BR cjpeg :
60.TP
61.B \-optimize
62Perform optimization of entropy encoding parameters.
63.TP
64.B \-progressive
65Create progressive JPEG file.
66.TP
67.BI \-restart " N"
68Emit a JPEG restart marker every N MCU rows, or every N MCU blocks if "B" is
69attached to the number.
70.TP
71.B \-arithmetic
72Use arithmetic coding.
73.TP
74.BI \-scans " file"
75Use the scan script given in the specified text file.
76.PP
77See
78.BR cjpeg (1)
79for more details about these switches.
80If you specify none of these switches, you get a plain baseline-JPEG output
81file. The quality setting and so forth are determined by the input file.
82.PP
83The image can be losslessly transformed by giving one of these switches:
84.TP
85.B \-flip horizontal
86Mirror image horizontally (left-right).
87.TP
88.B \-flip vertical
89Mirror image vertically (top-bottom).
90.TP
91.B \-rotate 90
92Rotate image 90 degrees clockwise.
93.TP
94.B \-rotate 180
95Rotate image 180 degrees.
96.TP
97.B \-rotate 270
98Rotate image 270 degrees clockwise (or 90 ccw).
99.TP
100.B \-transpose
101Transpose image (across UL-to-LR axis).
102.TP
103.B \-transverse
104Transverse transpose (across UR-to-LL axis).
105.PP
106The transpose transformation has no restrictions regarding image dimensions.
107The other transformations operate rather oddly if the image dimensions are not
108a multiple of the iMCU size (usually 8 or 16 pixels), because they can only
109transform complete blocks of DCT coefficient data in the desired way.
110.PP
111.BR jpegtran 's
112default behavior when transforming an odd-size image is designed
113to preserve exact reversibility and mathematical consistency of the
114transformation set. As stated, transpose is able to flip the entire image
115area. Horizontal mirroring leaves any partial iMCU column at the right edge
116untouched, but is able to flip all rows of the image. Similarly, vertical
117mirroring leaves any partial iMCU row at the bottom edge untouched, but is
118able to flip all columns. The other transforms can be built up as sequences
119of transpose and flip operations; for consistency, their actions on edge
120pixels are defined to be the same as the end result of the corresponding
121transpose-and-flip sequence.
122.PP
123For practical use, you may prefer to discard any untransformable edge pixels
124rather than having a strange-looking strip along the right and/or bottom edges
125of a transformed image. To do this, add the
126.B \-trim
127switch:
128.TP
129.B \-trim
130Drop non-transformable edge blocks.
131.IP
132Obviously, a transformation with
133.B \-trim
134is not reversible, so strictly speaking
135.B jpegtran
136with this switch is not lossless. Also, the expected mathematical
137equivalences between the transformations no longer hold. For example,
138.B \-rot 270 -trim
139trims only the bottom edge, but
140.B \-rot 90 -trim
141followed by
142.B \-rot 180 -trim
143trims both edges.
144.TP
145.B \-perfect
146If you are only interested in perfect transformations, add the
147.B \-perfect
148switch. This causes
149.B jpegtran
150to fail with an error if the transformation is not perfect.
151.IP
152For example, you may want to do
153.IP
154.B (jpegtran \-rot 90 -perfect
155.I foo.jpg
156.B || djpeg
157.I foo.jpg
158.B | pnmflip \-r90 | cjpeg)
159.IP
160to do a perfect rotation, if available, or an approximated one if not.
161.PP
162This version of \fBjpegtran\fR also offers a lossless crop option, which
163discards data outside of a given image region but losslessly preserves what is
Jonathan Wrightbbb82822020-11-25 13:36:43 +0000164inside. Like the rotate and flip transforms, lossless crop is restricted by
165the current JPEG format; the upper left corner of the selected region must fall
166on an iMCU boundary. If it doesn't, then it is silently moved up and/or left
167to the nearest iMCU boundary (the lower right corner is unchanged.) Thus, the
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400168output image covers at least the requested region, but it may cover more. The
Jonathan Wrightbbb82822020-11-25 13:36:43 +0000169adjustment of the region dimensions may be optionally disabled by attaching an
170'f' character ("force") to the width or height number.
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400171
172The image can be losslessly cropped by giving the switch:
173.TP
174.B \-crop WxH+X+Y
175Crop the image to a rectangular region of width W and height H, starting at
176point X,Y. The lossless crop feature discards data outside of a given image
177region but losslessly preserves what is inside. Like the rotate and flip
178transforms, lossless crop is restricted by the current JPEG format; the upper
179left corner of the selected region must fall on an iMCU boundary. If it
180doesn't, then it is silently moved up and/or left to the nearest iMCU boundary
181(the lower right corner is unchanged.)
182.PP
Jonathan Wrightbbb82822020-11-25 13:36:43 +0000183If W or H is larger than the width/height of the input image, then the output
184image 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
186will cause each block in the expanded region to be filled in with the DC
187coefficient of the nearest block in the input image rather than grayed out.
188Attaching an 'r' character ("reflect") to the width number will cause the
189expanded region to be filled in with repeated reflections of the input image
190rather than grayed out.
191.PP
192A complementary lossless wipe option is provided to discard (gray out) data
193inside a given image region while losslessly preserving what is outside:
194.TP
195.B \-wipe WxH+X+Y
196Wipe (gray out) a rectangular region of width W and height H from the input
197image, starting at point X,Y.
198.PP
199Attaching an 'f' character ("flatten") to the width number will cause the
200region to be filled with the average of adjacent blocks rather than grayed out.
201If the wipe region and the region outside the wipe region, when adjusted to the
202nearest iMCU boundary, form two horizontally adjacent rectangles, then
203attaching an 'r' character ("reflect") to the width number will cause the wipe
204region to be filled with repeated reflections of the outside region rather than
205grayed out.
206.PP
207A lossless drop option is also provided, which allows another JPEG image to be
208inserted ("dropped") into the input image data at a given position, replacing
209the existing image data at that position:
210.TP
211.B \-drop +X+Y filename
212Drop (insert) another image at point X,Y
213.PP
214Both the input image and the drop image must have the same subsampling level.
215It is best if they also have the same quantization (quality.) Otherwise, the
216quantization of the output image will be adapted to accommodate the higher of
217the input image quality and the drop image quality. The trim option can be
218used with the drop option to requantize the drop image to match the input
219image. Note that a grayscale image can be dropped into a full-color image or
220vice versa, as long as the full-color image has no vertical subsampling. If
221the input image is grayscale and the drop image is full-color, then the
222chrominance channels from the drop image will be discarded.
223.PP
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400224Other not-strictly-lossless transformation switches are:
225.TP
226.B \-grayscale
227Force grayscale output.
228.IP
229This option discards the chrominance channels if the input image is YCbCr
230(ie, a standard color JPEG), resulting in a grayscale JPEG file. The
231luminance channel is preserved exactly, so this is a better method of reducing
232to grayscale than decompression, conversion, and recompression. This switch
233is particularly handy for fixing a monochrome picture that was mistakenly
234encoded as a color JPEG. (In such a case, the space savings from getting rid
235of the near-empty chroma channels won't be large; but the decoding time for
236a grayscale JPEG is substantially less than that for a color JPEG.)
237.PP
238.B jpegtran
239also recognizes these switches that control what to do with "extra" markers,
240such as comment blocks:
241.TP
242.B \-copy none
243Copy no extra markers from source file. This setting suppresses all
244comments and other metadata in the source file.
245.TP
246.B \-copy comments
247Copy only comment markers. This setting copies comments from the source file
248but discards any other metadata.
249.TP
250.B \-copy all
251Copy all extra markers. This setting preserves miscellaneous markers
252found in the source file, such as JFIF thumbnails, Exif data, and Photoshop
253settings. In some files, these extra markers can be sizable. Note that this
254option will copy thumbnails as-is; they will not be transformed.
255.PP
256The default behavior is \fB-copy comments\fR. (Note: in IJG releases v6 and
257v6a, \fBjpegtran\fR always did the equivalent of \fB-copy none\fR.)
258.PP
259Additional switches recognized by jpegtran are:
260.TP
Chris Blumecca8c4d2019-03-01 01:09:50 -0800261.BI \-icc " file"
262Embed ICC color management profile contained in the specified file. Note that
263this will cause \fBjpegtran\fR to ignore any APP2 markers in the input file,
264even if \fB-copy all\fR is specified.
265.TP
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400266.BI \-maxmemory " N"
267Set limit for amount of memory to use in processing large images. Value is
268in thousands of bytes, or millions of bytes if "M" is attached to the
269number. For example,
270.B \-max 4m
Chris Blumecca8c4d2019-03-01 01:09:50 -0800271selects 4000000 bytes. If more space is needed, an error will occur.
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400272.TP
Jonathan Wrightbbb82822020-11-25 13:36:43 +0000273.BI \-maxscans " N"
274Abort if the input image contains more than
275.I N
276scans. This feature demonstrates a method by which applications can guard
277against denial-of-service attacks instigated by specially-crafted malformed
278JPEG images containing numerous scans with missing image data or image data
279consisting only of "EOB runs" (a feature of progressive JPEG images that allows
280potentially hundreds of thousands of adjoining zero-value pixels to be
281represented using only a few bytes.) Attempting to transform such malformed
282JPEG images can cause excessive CPU activity, since the decompressor must fully
283process each scan (even if the scan is corrupt) before it can proceed to the
284next scan.
285.TP
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400286.BI \-outfile " name"
287Send output image to the named file, not to standard output.
288.TP
Jonathan Wrightbbb82822020-11-25 13:36:43 +0000289.BI \-report
290Report transformation progress.
291.TP
292.BI \-strict
293Treat all warnings as fatal. This feature also demonstrates a method by which
294applications can guard against attacks instigated by specially-crafted
295malformed JPEG images. Enabling this option will cause the decompressor to
296abort if the input image contains incomplete or corrupt image data.
297.TP
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400298.B \-verbose
299Enable debug printout. More
300.BR \-v 's
301give more output. Also, version information is printed at startup.
302.TP
303.B \-debug
304Same as
305.BR \-verbose .
306.TP
307.B \-version
308Print version information and exit.
309.SH EXAMPLES
310.LP
311This example converts a baseline JPEG file to progressive form:
312.IP
313.B jpegtran \-progressive
314.I foo.jpg
315.B >
316.I fooprog.jpg
317.PP
318This example rotates an image 90 degrees clockwise, discarding any
319unrotatable edge pixels:
320.IP
321.B jpegtran \-rot 90 -trim
322.I foo.jpg
323.B >
324.I foo90.jpg
325.SH ENVIRONMENT
326.TP
327.B JPEGMEM
328If this environment variable is set, its value is the default memory limit.
329The value is specified as described for the
330.B \-maxmemory
331switch.
332.B JPEGMEM
333overrides the default value specified when the program was compiled, and
334itself is overridden by an explicit
335.BR \-maxmemory .
336.SH SEE ALSO
337.BR cjpeg (1),
338.BR djpeg (1),
339.BR rdjpgcom (1),
340.BR wrjpgcom (1)
341.br
342Wallace, Gregory K. "The JPEG Still Picture Compression Standard",
343Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
344.SH AUTHOR
345Independent JPEG Group
346.PP
347This file was modified by The libjpeg-turbo Project to include only information
348relevant to libjpeg-turbo and to wordsmith certain sections.
349.SH BUGS
350The transform options can't transform odd-size images perfectly. Use
351.B \-trim
352or
353.B \-perfect
354if you don't like the results.
355.PP
356The entire image is read into memory and then written out again, even in
357cases where this isn't really necessary. Expect swapping on large images,
358especially when using the more complex transform options.