blob: 66d2f9fedb0d293e7bda5dd9c7ffe8be5703c2c9 [file] [log] [blame]
DRC39ea5622010-10-12 01:55:31 +00001.TH JPEGTRAN 1 "11 October 2010"
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
22.B jpegtran
23works by rearranging the compressed data (DCT coefficients), without
24ever fully decoding the image. Therefore, its transformations are lossless:
25there is no image degradation at all, which would not be true if you used
Thomas G. Lanebc79e061995-08-02 00:00:00 +000026.B djpeg
27followed by
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000028.B cjpeg
29to accomplish the same conversion. But by the same token,
30.B jpegtran
31cannot perform lossy operations such as changing the image quality.
32.PP
Thomas G. Lanebc79e061995-08-02 00:00:00 +000033.B jpegtran
34reads the named JPEG/JFIF file, or the standard input if no file is
35named, and produces a JPEG/JFIF file on the standard output.
36.SH OPTIONS
Thomas G. Lanebc79e061995-08-02 00:00:00 +000037All switch names may be abbreviated; for example,
38.B \-optimize
39may be written
40.B \-opt
41or
42.BR \-o .
43Upper and lower case are equivalent.
44British spellings are also accepted (e.g.,
45.BR \-optimise ),
46though for brevity these are not mentioned below.
47.PP
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000048To specify the coded JPEG representation used in the output file,
49.B jpegtran
50accepts a subset of the switches recognized by
51.BR cjpeg :
Thomas G. Lanebc79e061995-08-02 00:00:00 +000052.TP
53.B \-optimize
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000054Perform optimization of entropy encoding parameters.
Thomas G. Lanebc79e061995-08-02 00:00:00 +000055.TP
56.B \-progressive
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000057Create progressive JPEG file.
Thomas G. Lanebc79e061995-08-02 00:00:00 +000058.TP
59.BI \-restart " N"
60Emit a JPEG restart marker every N MCU rows, or every N MCU blocks if "B" is
61attached to the number.
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000062.TP
63.BI \-scans " file"
64Use the scan script given in the specified text file.
65.PP
66See
67.BR cjpeg (1)
68for more details about these switches.
69If you specify none of these switches, you get a plain baseline-JPEG output
70file. The quality setting and so forth are determined by the input file.
71.PP
72The image can be losslessly transformed by giving one of these switches:
73.TP
74.B \-flip horizontal
75Mirror image horizontally (left-right).
76.TP
77.B \-flip vertical
78Mirror image vertically (top-bottom).
79.TP
80.B \-rotate 90
81Rotate image 90 degrees clockwise.
82.TP
83.B \-rotate 180
84Rotate image 180 degrees.
85.TP
86.B \-rotate 270
87Rotate image 270 degrees clockwise (or 90 ccw).
88.TP
89.B \-transpose
90Transpose image (across UL-to-LR axis).
91.TP
92.B \-transverse
93Transverse transpose (across UR-to-LL axis).
DRC39ea5622010-10-12 01:55:31 +000094.PP
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000095The transpose transformation has no restrictions regarding image dimensions.
96The other transformations operate rather oddly if the image dimensions are not
97a multiple of the iMCU size (usually 8 or 16 pixels), because they can only
98transform complete blocks of DCT coefficient data in the desired way.
DRC39ea5622010-10-12 01:55:31 +000099.PP
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000100.BR jpegtran 's
101default behavior when transforming an odd-size image is designed
102to preserve exact reversibility and mathematical consistency of the
103transformation set. As stated, transpose is able to flip the entire image
104area. Horizontal mirroring leaves any partial iMCU column at the right edge
105untouched, but is able to flip all rows of the image. Similarly, vertical
106mirroring leaves any partial iMCU row at the bottom edge untouched, but is
107able to flip all columns. The other transforms can be built up as sequences
108of transpose and flip operations; for consistency, their actions on edge
109pixels are defined to be the same as the end result of the corresponding
110transpose-and-flip sequence.
DRC39ea5622010-10-12 01:55:31 +0000111.PP
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000112For practical use, you may prefer to discard any untransformable edge pixels
113rather than having a strange-looking strip along the right and/or bottom edges
114of a transformed image. To do this, add the
115.B \-trim
116switch:
117.TP
118.B \-trim
119Drop non-transformable edge blocks.
Guido Vollbeding5996a252009-06-27 00:00:00 +0000120.IP
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000121Obviously, a transformation with
122.B \-trim
123is not reversible, so strictly speaking
124.B jpegtran
125with this switch is not lossless. Also, the expected mathematical
126equivalences between the transformations no longer hold. For example,
127.B \-rot 270 -trim
128trims only the bottom edge, but
129.B \-rot 90 -trim
130followed by
131.B \-rot 180 -trim
132trims both edges.
Guido Vollbeding5996a252009-06-27 00:00:00 +0000133.TP
134.B \-perfect
DRC39ea5622010-10-12 01:55:31 +0000135If you are only interested in perfect transformations, add the
136.B \-perfect
137switch. This causes
138.B jpegtran
139to fail with an error if the transformation is not perfect.
Guido Vollbeding5996a252009-06-27 00:00:00 +0000140.IP
DRC39ea5622010-10-12 01:55:31 +0000141For example, you may want to do
Guido Vollbeding5996a252009-06-27 00:00:00 +0000142.IP
143.B (jpegtran \-rot 90 -perfect
144.I foo.jpg
145.B || djpeg
146.I foo.jpg
147.B | pnmflip \-r90 | cjpeg)
148.IP
DRC39ea5622010-10-12 01:55:31 +0000149to do a perfect rotation, if available, or an approximated one if not.
Guido Vollbeding5996a252009-06-27 00:00:00 +0000150.TP
151.B \-crop WxH+X+Y
DRC39ea5622010-10-12 01:55:31 +0000152Crop the image to a rectangular region of width W and height H, starting at
153point X,Y. The lossless crop feature discards data outside of a given image
154region but losslessly preserves what is inside. Like the rotate and flip
155transforms, lossless crop is restricted by the current JPEG format; the upper
156left corner of the selected region must fall on an iMCU boundary. If it
157doesn't, then it is silently moved up and/or left to the nearest iMCU boundary
158(the lower right corner is unchanged.)
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000159.PP
Guido Vollbeding989630f2010-01-10 00:00:00 +0000160Other not-strictly-lossless transformation switches are:
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000161.TP
162.B \-grayscale
163Force grayscale output.
Guido Vollbeding5996a252009-06-27 00:00:00 +0000164.IP
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000165This option discards the chrominance channels if the input image is YCbCr
166(ie, a standard color JPEG), resulting in a grayscale JPEG file. The
167luminance channel is preserved exactly, so this is a better method of reducing
168to grayscale than decompression, conversion, and recompression. This switch
169is particularly handy for fixing a monochrome picture that was mistakenly
170encoded as a color JPEG. (In such a case, the space savings from getting rid
171of the near-empty chroma channels won't be large; but the decoding time for
172a grayscale JPEG is substantially less than that for a color JPEG.)
173.PP
174.B jpegtran
175also recognizes these switches that control what to do with "extra" markers,
176such as comment blocks:
177.TP
178.B \-copy none
179Copy no extra markers from source file. This setting suppresses all
180comments and other excess baggage present in the source file.
181.TP
182.B \-copy comments
DRC39ea5622010-10-12 01:55:31 +0000183Copy only comment markers. This setting copies comments from the source file
184but discards any other data which is inessential for image display.
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000185.TP
186.B \-copy all
187Copy all extra markers. This setting preserves miscellaneous markers
Guido Vollbeding5996a252009-06-27 00:00:00 +0000188found in the source file, such as JFIF thumbnails, Exif data, and Photoshop
DRC39ea5622010-10-12 01:55:31 +0000189settings. In some files, these extra markers can be sizable.
190.PP
191The default behavior is \fB-copy comments\fR. (Note: in IJG releases v6 and
192v6a, \fBjpegtran\fR always did the equivalent of \fB-copy none\fR.)
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000193.PP
194Additional switches recognized by jpegtran are:
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000195.TP
196.BI \-maxmemory " N"
197Set limit for amount of memory to use in processing large images. Value is
198in thousands of bytes, or millions of bytes if "M" is attached to the
199number. For example,
200.B \-max 4m
201selects 4000000 bytes. If more space is needed, temporary files will be used.
202.TP
203.BI \-outfile " name"
204Send output image to the named file, not to standard output.
205.TP
206.B \-verbose
207Enable debug printout. More
208.BR \-v 's
209give more output. Also, version information is printed at startup.
210.TP
211.B \-debug
212Same as
213.BR \-verbose .
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000214.SH EXAMPLES
215.LP
216This example converts a baseline JPEG file to progressive form:
217.IP
218.B jpegtran \-progressive
219.I foo.jpg
220.B >
221.I fooprog.jpg
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000222.PP
223This example rotates an image 90 degrees clockwise, discarding any
224unrotatable edge pixels:
225.IP
226.B jpegtran \-rot 90 -trim
227.I foo.jpg
228.B >
229.I foo90.jpg
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000230.SH ENVIRONMENT
231.TP
232.B JPEGMEM
233If this environment variable is set, its value is the default memory limit.
234The value is specified as described for the
235.B \-maxmemory
236switch.
237.B JPEGMEM
238overrides the default value specified when the program was compiled, and
239itself is overridden by an explicit
240.BR \-maxmemory .
241.SH SEE ALSO
242.BR cjpeg (1),
243.BR djpeg (1),
244.BR rdjpgcom (1),
245.BR wrjpgcom (1)
246.br
247Wallace, Gregory K. "The JPEG Still Picture Compression Standard",
248Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
249.SH AUTHOR
250Independent JPEG Group
251.SH BUGS
252Arithmetic coding is not supported for legal reasons.
253.PP
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000254The transform options can't transform odd-size images perfectly. Use
255.B \-trim
Guido Vollbeding5996a252009-06-27 00:00:00 +0000256or
257.B \-perfect
258if you don't like the results.
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000259.PP
260The entire image is read into memory and then written out again, even in
261cases where this isn't really necessary. Expect swapping on large images,
262especially when using the more complex transform options.