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