jpegtran
Transform and optimize JPEG images losslessly
TLDR
Mirror an image horizontally or vertically
Rotate an image 90, 180, or 270 degrees clockwise
Transpose the image across the upper-left to lower right axis
Transverse the image across the upper right to lower left axis
Convert the image to grayscale
Crop the image to a rectangular region of width W and height H from the upper-left corner, saving the output to a specific file
Crop the image to a rectangular region of width W and height H, starting at point X and Y from the upper-left corner
SYNOPSIS
jpegtran [options] inputfile [outputfile]
PARAMETERS
-arithmetic
Use arithmetic entropy coding instead of Huffman.
-copy none|comments|all|exif
Copy specified APPn markers/metadata to output; default copies comments.
-crop WxH+x+y
Losslessly crop to given widthxheight+xoffset+yoffset (iMCU-aligned).
-dct int|float
Select DCT method: int (default, fast) or float (precise).
-drop none|any|all
Drop non-APPn markers: none (default), any except JFIF/Adobe, or all.
-flip horizontal|vertical
Mirror image horizontally or vertically.
-maxmemory N
Limit memory usage to N megabytes.
-optimize
Optimize entropy coding tables for smaller files.
-outfile name
Write output to named file (default stdout).
-perfect
Use perfect Huffman trees (slower, larger than -optimize).
-progressive
Convert to baseline progressive JPEG.
-restart N
Set restart interval to N MCU rows.
-rotate 90|180|270
Rotate clockwise by 90, 180, or 270 degrees.
-scale 1/2|1/4|1/8
Losslessly downscale by integer factor.
-transpose
Transpose across UL-to-LR axis.
-transverse
Transverse transpose across UR-to-LL axis.
-trim
Trim off partial iMCU blocks at edges.
-verbose
Enable verbose output.
DESCRIPTION
jpegtran is a utility from the Independent JPEG Group's libjpeg library for performing lossless transformations on JPEG images. It allows operations like rotation, flipping, cropping, trimming, and scaling without re-encoding the image data, preserving original quality.
Key features include optimizing Huffman tables for smaller file sizes (-optimize), converting to progressive JPEG (-progressive), and handling metadata with -copy options. It supports downscaling by factors of 1/2, 1/4, or 1/8 (-scale), and can drop unnecessary markers to reduce size.
Unlike lossy tools, jpegtran rearranges the existing DCT coefficients, making it ideal for batch processing photos for web or storage. It reads from stdin or files and writes to stdout or specified output, with verbose mode for progress. Limitations apply to crop boundaries (must align with iMCU blocks), but -trim helps with ragged edges. Widely used in image workflows, it's faster and safer than re-encoding with converters like ImageMagick's mogrify.
CAVEATS
Crops must align with iMCU grid (8-16 pixel blocks); use -trim for auto-adjust. No support for non-JPEG input. Optimized files may not be smaller if already optimal.
COMMON USAGE
Optimize: jpegtran -optimize -outfile out.jpg in.jpg
Rotate: jpegtran -rotate 90 -copy all -outfile out.jpg in.jpg
Progressive: jpegtran -progressive -optimize input.jpg > output.jpg
HISTORY
Developed by Independent JPEG Group (IJG); first released in 1991 as part of libjpeg v5. Ongoing maintenance in libjpeg-turbo fork for speed improvements.


