jpegtran Command Examples in Linux

jpegtran is a command-line tool that can perform lossless transformations on JPEG image files. Lossless transformations are modifications to the image file that do not result in any loss of quality or information.

Some common jpegtran options include:

  • -rotate [angle]: this option allows you to rotate the image by the specified angle (90, 180, or 270)
  • -flip [axis]: this option allows you to flip the image on the specified axis (horizontal or vertical)
  • -trim: this option will remove any unnecessary padding around the image
  • -outfile [outputfile]: This option allows you to specify the name of the output file

Jpegtran is a useful tool for optimizing and transforming JPEG image files without losing any quality or information. It can be used to reduce file size, improve the compression, rotate or flip images, and trim the unnecessary parts of the image. Jpegtran is available on most Unix-like operating systems including Linux and macOS.

jpegtran Command Examples

1. Mirror an image horizontally or vertically:

# jpegtran -flip horizontal|vertical path/to/image.jpg > path/to/output.jpg

2. Rotate an image 90, 180 or 270 degrees clockwise:

# jpegtran -rotate 90|180|270 path/to/image.jpg > path/to/output.jpg

3. Transpose the image across the upper-left to lower right axis:

# jpegtran -transpose path/to/image.jpg > path/to/output.jpg

4. Transverse the image across the upper right to lower left axis:

# jpegtran -transverse path/to/image.jpg > path/to/output.jpg

5. Convert the image to grayscale:

# jpegtran -grayscale path/to/image.jpg > path/to/output.jpg

6. 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:

# jpegtran -crop WxH -outfile path/to/output.jpg path/to/image.jpg

7. Crop the image to a rectangular region of width `W` and height `H`, starting at point `X` and `Y` from the upper-left corner:

# jpegtran -crop WxH+X+Y path/to/image.jpg > path/to/output.jpg
Related Post