shun-iwasawa 82a8f5
.TH JPEGTRAN 1 "18 March 2017"
kusano 7d535a
.SH NAME
kusano 7d535a
jpegtran \- lossless transformation of JPEG files
kusano 7d535a
.SH SYNOPSIS
kusano 7d535a
.B jpegtran
kusano 7d535a
[
kusano 7d535a
.I options
kusano 7d535a
]
kusano 7d535a
[
kusano 7d535a
.I filename
kusano 7d535a
]
kusano 7d535a
.LP
kusano 7d535a
.SH DESCRIPTION
kusano 7d535a
.LP
kusano 7d535a
.B jpegtran
kusano 7d535a
performs various useful transformations of JPEG files.
kusano 7d535a
It can translate the coded representation from one variant of JPEG to another,
kusano 7d535a
for example from baseline JPEG to progressive JPEG or vice versa.  It can also
kusano 7d535a
perform some rearrangements of the image data, for example turning an image
kusano 7d535a
from landscape to portrait format by rotation.
kusano 7d535a
.PP
shun-iwasawa 82a8f5
For EXIF files and JPEG files containing Exif data, you may prefer to use
shun-iwasawa 82a8f5
.B exiftran
shun-iwasawa 82a8f5
instead.
shun-iwasawa 82a8f5
.PP
kusano 7d535a
.B jpegtran
kusano 7d535a
works by rearranging the compressed data (DCT coefficients), without
kusano 7d535a
ever fully decoding the image.  Therefore, its transformations are lossless:
kusano 7d535a
there is no image degradation at all, which would not be true if you used
kusano 7d535a
.B djpeg
kusano 7d535a
followed by
kusano 7d535a
.B cjpeg
kusano 7d535a
to accomplish the same conversion.  But by the same token,
kusano 7d535a
.B jpegtran
shun-iwasawa 82a8f5
cannot perform lossy operations such as changing the image quality.  However,
shun-iwasawa 82a8f5
while the image data is losslessly transformed, metadata can be removed.  See
shun-iwasawa 82a8f5
the
shun-iwasawa 82a8f5
.B \-copy
shun-iwasawa 82a8f5
option for specifics.
kusano 7d535a
.PP
kusano 7d535a
.B jpegtran
kusano 7d535a
reads the named JPEG/JFIF file, or the standard input if no file is
kusano 7d535a
named, and produces a JPEG/JFIF file on the standard output.
kusano 7d535a
.SH OPTIONS
kusano 7d535a
All switch names may be abbreviated; for example,
kusano 7d535a
.B \-optimize
kusano 7d535a
may be written
kusano 7d535a
.B \-opt
kusano 7d535a
or
kusano 7d535a
.BR \-o .
kusano 7d535a
Upper and lower case are equivalent.
kusano 7d535a
British spellings are also accepted (e.g.,
kusano 7d535a
.BR \-optimise ),
kusano 7d535a
though for brevity these are not mentioned below.
kusano 7d535a
.PP
kusano 7d535a
To specify the coded JPEG representation used in the output file,
kusano 7d535a
.B jpegtran
kusano 7d535a
accepts a subset of the switches recognized by
kusano 7d535a
.BR cjpeg :
kusano 7d535a
.TP
kusano 7d535a
.B \-optimize
kusano 7d535a
Perform optimization of entropy encoding parameters.
kusano 7d535a
.TP
kusano 7d535a
.B \-progressive
kusano 7d535a
Create progressive JPEG file.
kusano 7d535a
.TP
kusano 7d535a
.BI \-restart " N"
kusano 7d535a
Emit a JPEG restart marker every N MCU rows, or every N MCU blocks if "B" is
kusano 7d535a
attached to the number.
kusano 7d535a
.TP
kusano 7d535a
.B \-arithmetic
kusano 7d535a
Use arithmetic coding.
kusano 7d535a
.TP
kusano 7d535a
.BI \-scans " file"
kusano 7d535a
Use the scan script given in the specified text file.
kusano 7d535a
.PP
kusano 7d535a
See
kusano 7d535a
.BR cjpeg (1)
kusano 7d535a
for more details about these switches.
kusano 7d535a
If you specify none of these switches, you get a plain baseline-JPEG output
kusano 7d535a
file.  The quality setting and so forth are determined by the input file.
kusano 7d535a
.PP
kusano 7d535a
The image can be losslessly transformed by giving one of these switches:
kusano 7d535a
.TP
kusano 7d535a
.B \-flip horizontal
kusano 7d535a
Mirror image horizontally (left-right).
kusano 7d535a
.TP
kusano 7d535a
.B \-flip vertical
kusano 7d535a
Mirror image vertically (top-bottom).
kusano 7d535a
.TP
kusano 7d535a
.B \-rotate 90
kusano 7d535a
Rotate image 90 degrees clockwise.
kusano 7d535a
.TP
kusano 7d535a
.B \-rotate 180
kusano 7d535a
Rotate image 180 degrees.
kusano 7d535a
.TP
kusano 7d535a
.B \-rotate 270
kusano 7d535a
Rotate image 270 degrees clockwise (or 90 ccw).
kusano 7d535a
.TP
kusano 7d535a
.B \-transpose
kusano 7d535a
Transpose image (across UL-to-LR axis).
kusano 7d535a
.TP
kusano 7d535a
.B \-transverse
kusano 7d535a
Transverse transpose (across UR-to-LL axis).
shun-iwasawa 82a8f5
.PP
kusano 7d535a
The transpose transformation has no restrictions regarding image dimensions.
kusano 7d535a
The other transformations operate rather oddly if the image dimensions are not
kusano 7d535a
a multiple of the iMCU size (usually 8 or 16 pixels), because they can only
kusano 7d535a
transform complete blocks of DCT coefficient data in the desired way.
shun-iwasawa 82a8f5
.PP
kusano 7d535a
.BR jpegtran 's
kusano 7d535a
default behavior when transforming an odd-size image is designed
kusano 7d535a
to preserve exact reversibility and mathematical consistency of the
kusano 7d535a
transformation set.  As stated, transpose is able to flip the entire image
kusano 7d535a
area.  Horizontal mirroring leaves any partial iMCU column at the right edge
kusano 7d535a
untouched, but is able to flip all rows of the image.  Similarly, vertical
kusano 7d535a
mirroring leaves any partial iMCU row at the bottom edge untouched, but is
kusano 7d535a
able to flip all columns.  The other transforms can be built up as sequences
kusano 7d535a
of transpose and flip operations; for consistency, their actions on edge
kusano 7d535a
pixels are defined to be the same as the end result of the corresponding
kusano 7d535a
transpose-and-flip sequence.
shun-iwasawa 82a8f5
.PP
kusano 7d535a
For practical use, you may prefer to discard any untransformable edge pixels
kusano 7d535a
rather than having a strange-looking strip along the right and/or bottom edges
kusano 7d535a
of a transformed image.  To do this, add the
kusano 7d535a
.B \-trim
kusano 7d535a
switch:
kusano 7d535a
.TP
kusano 7d535a
.B \-trim
kusano 7d535a
Drop non-transformable edge blocks.
kusano 7d535a
.IP
kusano 7d535a
Obviously, a transformation with
kusano 7d535a
.B \-trim
kusano 7d535a
is not reversible, so strictly speaking
kusano 7d535a
.B jpegtran
kusano 7d535a
with this switch is not lossless.  Also, the expected mathematical
kusano 7d535a
equivalences between the transformations no longer hold.  For example,
kusano 7d535a
.B \-rot 270 -trim
kusano 7d535a
trims only the bottom edge, but
kusano 7d535a
.B \-rot 90 -trim
kusano 7d535a
followed by
kusano 7d535a
.B \-rot 180 -trim
kusano 7d535a
trims both edges.
kusano 7d535a
.TP
kusano 7d535a
.B \-perfect
shun-iwasawa 82a8f5
If you are only interested in perfect transformations, add the
shun-iwasawa 82a8f5
.B \-perfect
shun-iwasawa 82a8f5
switch.  This causes
shun-iwasawa 82a8f5
.B jpegtran
shun-iwasawa 82a8f5
to fail with an error if the transformation is not perfect.
kusano 7d535a
.IP
shun-iwasawa 82a8f5
For example, you may want to do
kusano 7d535a
.IP
kusano 7d535a
.B (jpegtran \-rot 90 -perfect
kusano 7d535a
.I foo.jpg
kusano 7d535a
.B || djpeg
kusano 7d535a
.I foo.jpg
kusano 7d535a
.B | pnmflip \-r90 | cjpeg)
kusano 7d535a
.IP
shun-iwasawa 82a8f5
to do a perfect rotation, if available, or an approximated one if not.
kusano 7d535a
.PP
shun-iwasawa 82a8f5
This version of \fBjpegtran\fR also offers a lossless crop option, which
shun-iwasawa 82a8f5
discards data outside of a given image region but losslessly preserves what is
shun-iwasawa 82a8f5
inside.  Like the rotate and flip transforms, lossless crop is restricted by
shun-iwasawa 82a8f5
the current JPEG format; the upper left corner of the selected region must fall
shun-iwasawa 82a8f5
on an iMCU boundary.  If it doesn't, then it is silently moved up and/or left
shun-iwasawa 82a8f5
to the nearest iMCU boundary (the lower right corner is unchanged.)  Thus, the
shun-iwasawa 82a8f5
output image covers at least the requested region, but it may cover more.  The
shun-iwasawa 82a8f5
adjustment of the region dimensions may be optionally disabled by attaching an
shun-iwasawa 82a8f5
'f' character ("force") to the width or height number.
kusano 7d535a
kusano 7d535a
The image can be losslessly cropped by giving the switch:
kusano 7d535a
.TP
kusano 7d535a
.B \-crop WxH+X+Y
shun-iwasawa 82a8f5
Crop the image to a rectangular region of width W and height H, starting at
shun-iwasawa 82a8f5
point X,Y.  The lossless crop feature discards data outside of a given image
shun-iwasawa 82a8f5
region but losslessly preserves what is inside.  Like the rotate and flip
shun-iwasawa 82a8f5
transforms, lossless crop is restricted by the current JPEG format; the upper
shun-iwasawa 82a8f5
left corner of the selected region must fall on an iMCU boundary.  If it
shun-iwasawa 82a8f5
doesn't, then it is silently moved up and/or left to the nearest iMCU boundary
shun-iwasawa 82a8f5
(the lower right corner is unchanged.)
kusano 7d535a
.PP
kusano 7d535a
Other not-strictly-lossless transformation switches are:
kusano 7d535a
.TP
kusano 7d535a
.B \-grayscale
kusano 7d535a
Force grayscale output.
kusano 7d535a
.IP
kusano 7d535a
This option discards the chrominance channels if the input image is YCbCr
kusano 7d535a
(ie, a standard color JPEG), resulting in a grayscale JPEG file.  The
kusano 7d535a
luminance channel is preserved exactly, so this is a better method of reducing
kusano 7d535a
to grayscale than decompression, conversion, and recompression.  This switch
kusano 7d535a
is particularly handy for fixing a monochrome picture that was mistakenly
kusano 7d535a
encoded as a color JPEG.  (In such a case, the space savings from getting rid
kusano 7d535a
of the near-empty chroma channels won't be large; but the decoding time for
kusano 7d535a
a grayscale JPEG is substantially less than that for a color JPEG.)
kusano 7d535a
.PP
kusano 7d535a
.B jpegtran
kusano 7d535a
also recognizes these switches that control what to do with "extra" markers,
kusano 7d535a
such as comment blocks:
kusano 7d535a
.TP
kusano 7d535a
.B \-copy none
kusano 7d535a
Copy no extra markers from source file.  This setting suppresses all
shun-iwasawa 82a8f5
comments and other metadata in the source file.
kusano 7d535a
.TP
kusano 7d535a
.B \-copy comments
shun-iwasawa 82a8f5
Copy only comment markers.  This setting copies comments from the source file
shun-iwasawa 82a8f5
but discards any other metadata.
kusano 7d535a
.TP
kusano 7d535a
.B \-copy all
kusano 7d535a
Copy all extra markers.  This setting preserves miscellaneous markers
kusano 7d535a
found in the source file, such as JFIF thumbnails, Exif data, and Photoshop
shun-iwasawa 82a8f5
settings.  In some files, these extra markers can be sizable.  Note that this
shun-iwasawa 82a8f5
option will copy thumbnails as-is; they will not be transformed.
shun-iwasawa 82a8f5
.PP
shun-iwasawa 82a8f5
The default behavior is \fB-copy comments\fR.  (Note: in IJG releases v6 and
shun-iwasawa 82a8f5
v6a, \fBjpegtran\fR always did the equivalent of \fB-copy none\fR.)
kusano 7d535a
.PP
kusano 7d535a
Additional switches recognized by jpegtran are:
kusano 7d535a
.TP
shun-iwasawa 82a8f5
.BI \-icc " file"
shun-iwasawa 82a8f5
Embed ICC color management profile contained in the specified file.  Note that
shun-iwasawa 82a8f5
this will cause \fBjpegtran\fR to ignore any APP2 markers in the input file,
shun-iwasawa 82a8f5
even if \fB-copy all\fR is specified.
shun-iwasawa 82a8f5
.TP
kusano 7d535a
.BI \-maxmemory " N"
kusano 7d535a
Set limit for amount of memory to use in processing large images.  Value is
kusano 7d535a
in thousands of bytes, or millions of bytes if "M" is attached to the
kusano 7d535a
number.  For example,
kusano 7d535a
.B \-max 4m
shun-iwasawa 82a8f5
selects 4000000 bytes.  If more space is needed, an error will occur.
kusano 7d535a
.TP
kusano 7d535a
.BI \-outfile " name"
kusano 7d535a
Send output image to the named file, not to standard output.
kusano 7d535a
.TP
kusano 7d535a
.B \-verbose
kusano 7d535a
Enable debug printout.  More
kusano 7d535a
.BR \-v 's
kusano 7d535a
give more output.  Also, version information is printed at startup.
kusano 7d535a
.TP
kusano 7d535a
.B \-debug
kusano 7d535a
Same as
kusano 7d535a
.BR \-verbose .
shun-iwasawa 82a8f5
.TP
shun-iwasawa 82a8f5
.B \-version
shun-iwasawa 82a8f5
Print version information and exit.
kusano 7d535a
.SH EXAMPLES
kusano 7d535a
.LP
kusano 7d535a
This example converts a baseline JPEG file to progressive form:
kusano 7d535a
.IP
kusano 7d535a
.B jpegtran \-progressive
kusano 7d535a
.I foo.jpg
kusano 7d535a
.B >
kusano 7d535a
.I fooprog.jpg
kusano 7d535a
.PP
kusano 7d535a
This example rotates an image 90 degrees clockwise, discarding any
kusano 7d535a
unrotatable edge pixels:
kusano 7d535a
.IP
kusano 7d535a
.B jpegtran \-rot 90 -trim
kusano 7d535a
.I foo.jpg
kusano 7d535a
.B >
kusano 7d535a
.I foo90.jpg
kusano 7d535a
.SH ENVIRONMENT
kusano 7d535a
.TP
kusano 7d535a
.B JPEGMEM
kusano 7d535a
If this environment variable is set, its value is the default memory limit.
kusano 7d535a
The value is specified as described for the
kusano 7d535a
.B \-maxmemory
kusano 7d535a
switch.
kusano 7d535a
.B JPEGMEM
kusano 7d535a
overrides the default value specified when the program was compiled, and
kusano 7d535a
itself is overridden by an explicit
kusano 7d535a
.BR \-maxmemory .
kusano 7d535a
.SH SEE ALSO
kusano 7d535a
.BR cjpeg (1),
kusano 7d535a
.BR djpeg (1),
kusano 7d535a
.BR rdjpgcom (1),
kusano 7d535a
.BR wrjpgcom (1)
kusano 7d535a
.br
kusano 7d535a
Wallace, Gregory K.  "The JPEG Still Picture Compression Standard",
kusano 7d535a
Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
kusano 7d535a
.SH AUTHOR
kusano 7d535a
Independent JPEG Group
shun-iwasawa 82a8f5
.PP
shun-iwasawa 82a8f5
This file was modified by The libjpeg-turbo Project to include only information
shun-iwasawa 82a8f5
relevant to libjpeg-turbo and to wordsmith certain sections.
kusano 7d535a
.SH BUGS
kusano 7d535a
The transform options can't transform odd-size images perfectly.  Use
kusano 7d535a
.B \-trim
kusano 7d535a
or
kusano 7d535a
.B \-perfect
kusano 7d535a
if you don't like the results.
kusano 7d535a
.PP
kusano 7d535a
The entire image is read into memory and then written out again, even in
kusano 7d535a
cases where this isn't really necessary.  Expect swapping on large images,
kusano 7d535a
especially when using the more complex transform options.