blob: 2efb26472acf17dfb660e2db4a409bed6fd2429b [file] [log] [blame]
Leon Scroggins IIIbd7903e2018-02-28 14:05:04 -05001.TH JPEGTRAN 1 "18 March 2017"
Thomas G. Lanebc79e061995-08-02 00:00:00 +00002.SH NAME
Thomas G. Lane5ead57a1998-03-27 00:00:00 +00003jpegtran \- lossless transformation of JPEG files
Thomas G. Lanebc79e061995-08-02 00:00:00 +00004.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
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000016performs 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
Alex Naidis6eb7d372016-10-16 23:10:08 +020022For EXIF files and JPEG files containing Exif data, you may prefer to use
23.B exiftran
24instead.
25.PP
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000026.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
Thomas G. Lanebc79e061995-08-02 00:00:00 +000030.B djpeg
31followed by
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000032.B cjpeg
33to accomplish the same conversion. But by the same token,
34.B jpegtran
Alex Naidis6eb7d372016-10-16 23:10:08 +020035cannot 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.
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000040.PP
Thomas G. Lanebc79e061995-08-02 00:00:00 +000041.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
Thomas G. Lanebc79e061995-08-02 00:00:00 +000045All 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
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000056To specify the coded JPEG representation used in the output file,
57.B jpegtran
58accepts a subset of the switches recognized by
59.BR cjpeg :
Thomas G. Lanebc79e061995-08-02 00:00:00 +000060.TP
61.B \-optimize
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000062Perform optimization of entropy encoding parameters.
Thomas G. Lanebc79e061995-08-02 00:00:00 +000063.TP
64.B \-progressive
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000065Create progressive JPEG file.
Thomas G. Lanebc79e061995-08-02 00:00:00 +000066.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.
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000070.TP
Guido Vollbeding5996a252009-06-27 00:00:00 +000071.B \-arithmetic
72Use arithmetic coding.
73.TP
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000074.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).
DRC39ea5622010-10-12 01:55:31 +0000105.PP
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000106The 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.
DRC39ea5622010-10-12 01:55:31 +0000110.PP
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000111.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.
DRC39ea5622010-10-12 01:55:31 +0000122.PP
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000123For 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.
Guido Vollbeding5996a252009-06-27 00:00:00 +0000131.IP
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000132Obviously, 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.
Guido Vollbeding5996a252009-06-27 00:00:00 +0000144.TP
145.B \-perfect
DRC39ea5622010-10-12 01:55:31 +0000146If 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.
Guido Vollbeding5996a252009-06-27 00:00:00 +0000151.IP
DRC39ea5622010-10-12 01:55:31 +0000152For example, you may want to do
Guido Vollbeding5996a252009-06-27 00:00:00 +0000153.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
DRC39ea5622010-10-12 01:55:31 +0000160to do a perfect rotation, if available, or an approximated one if not.
Alex Naidis6eb7d372016-10-16 23:10:08 +0200161.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
164inside. Like the rotate and flip transforms, lossless crop is restricted by the
165current JPEG format; the upper left corner of the selected region must fall on
166an iMCU boundary. If it doesn't, then it is silently moved up and/or left to
167the nearest iMCU boundary (the lower right corner is unchanged.) Thus, the
168output image covers at least the requested region, but it may cover more. The
169adjustment of the region dimensions may be optionally disabled by attaching
170an 'f' character ("force") to the width or height number.
171
172The image can be losslessly cropped by giving the switch:
Guido Vollbeding5996a252009-06-27 00:00:00 +0000173.TP
174.B \-crop WxH+X+Y
DRC39ea5622010-10-12 01:55:31 +0000175Crop 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.)
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000182.PP
Guido Vollbeding989630f2010-01-10 00:00:00 +0000183Other not-strictly-lossless transformation switches are:
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000184.TP
185.B \-grayscale
186Force grayscale output.
Guido Vollbeding5996a252009-06-27 00:00:00 +0000187.IP
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000188This option discards the chrominance channels if the input image is YCbCr
189(ie, a standard color JPEG), resulting in a grayscale JPEG file. The
190luminance channel is preserved exactly, so this is a better method of reducing
191to grayscale than decompression, conversion, and recompression. This switch
192is particularly handy for fixing a monochrome picture that was mistakenly
193encoded as a color JPEG. (In such a case, the space savings from getting rid
194of the near-empty chroma channels won't be large; but the decoding time for
195a grayscale JPEG is substantially less than that for a color JPEG.)
196.PP
197.B jpegtran
198also recognizes these switches that control what to do with "extra" markers,
199such as comment blocks:
200.TP
201.B \-copy none
202Copy no extra markers from source file. This setting suppresses all
Alex Naidis6eb7d372016-10-16 23:10:08 +0200203comments and other metadata in the source file.
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000204.TP
205.B \-copy comments
DRC39ea5622010-10-12 01:55:31 +0000206Copy only comment markers. This setting copies comments from the source file
Alex Naidis6eb7d372016-10-16 23:10:08 +0200207but discards any other metadata.
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000208.TP
209.B \-copy all
210Copy all extra markers. This setting preserves miscellaneous markers
Guido Vollbeding5996a252009-06-27 00:00:00 +0000211found in the source file, such as JFIF thumbnails, Exif data, and Photoshop
Alex Naidis6eb7d372016-10-16 23:10:08 +0200212settings. In some files, these extra markers can be sizable. Note that this
213option will copy thumbnails as-is; they will not be transformed.
DRC39ea5622010-10-12 01:55:31 +0000214.PP
215The default behavior is \fB-copy comments\fR. (Note: in IJG releases v6 and
216v6a, \fBjpegtran\fR always did the equivalent of \fB-copy none\fR.)
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000217.PP
218Additional switches recognized by jpegtran are:
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000219.TP
Leon Scroggins III3993b372018-07-16 10:43:45 -0400220.BI \-icc " file"
221Embed ICC color management profile contained in the specified file. Note that
222this will cause \fBjpegtran\fR to ignore any APP2 markers in the input file,
223even if \fB-copy all\fR is specified.
224.TP
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000225.BI \-maxmemory " N"
226Set limit for amount of memory to use in processing large images. Value is
227in thousands of bytes, or millions of bytes if "M" is attached to the
228number. For example,
229.B \-max 4m
Leon Scroggins IIIbd7903e2018-02-28 14:05:04 -0500230selects 4000000 bytes. If more space is needed, an error will occur.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000231.TP
232.BI \-outfile " name"
233Send output image to the named file, not to standard output.
234.TP
235.B \-verbose
236Enable debug printout. More
237.BR \-v 's
238give more output. Also, version information is printed at startup.
239.TP
240.B \-debug
241Same as
242.BR \-verbose .
DRC9665f5e2014-11-22 04:04:38 +0000243.TP
244.B \-version
245Print version information and exit.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000246.SH EXAMPLES
247.LP
248This example converts a baseline JPEG file to progressive form:
249.IP
250.B jpegtran \-progressive
251.I foo.jpg
252.B >
253.I fooprog.jpg
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000254.PP
255This example rotates an image 90 degrees clockwise, discarding any
256unrotatable edge pixels:
257.IP
258.B jpegtran \-rot 90 -trim
259.I foo.jpg
260.B >
261.I foo90.jpg
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000262.SH ENVIRONMENT
263.TP
264.B JPEGMEM
265If this environment variable is set, its value is the default memory limit.
266The value is specified as described for the
267.B \-maxmemory
268switch.
269.B JPEGMEM
270overrides the default value specified when the program was compiled, and
271itself is overridden by an explicit
272.BR \-maxmemory .
273.SH SEE ALSO
274.BR cjpeg (1),
275.BR djpeg (1),
276.BR rdjpgcom (1),
277.BR wrjpgcom (1)
278.br
279Wallace, Gregory K. "The JPEG Still Picture Compression Standard",
280Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
281.SH AUTHOR
282Independent JPEG Group
DRC251db632013-01-01 10:51:16 +0000283.PP
284This file was modified by The libjpeg-turbo Project to include only information
285relevant to libjpeg-turbo and to wordsmith certain sections.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000286.SH BUGS
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000287The transform options can't transform odd-size images perfectly. Use
288.B \-trim
Guido Vollbeding5996a252009-06-27 00:00:00 +0000289or
290.B \-perfect
291if you don't like the results.
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000292.PP
293The entire image is read into memory and then written out again, even in
294cases where this isn't really necessary. Expect swapping on large images,
295especially when using the more complex transform options.