rotate images from the Linux command line
Two tools for rotating images from the command line are
jpegtran transforms JPEG files. It can translate the coded representation from one variant of JPEG to another, for example from baseline JPEG to progressive JPEG or vice versa. It can also perform some rearrangements of the image data, for example turning an image from landscape to portrait format by rotation. The transpose transformation has no restrictions regarding image dimensions.
jpegtran's default behaviour when transforming an odd-size image is designed to preserve exact reversibility and mathematical consistency of the transformation set.
The command to rotate
input.jpg 90 degrees clockwise and save the result to
jpegtran -rotate 90 input.jpg output.jpg
All switch names may be abbreviated; for example, -optimize may be written
-o. Upper and lower case are equivalent. British spellings are also accepted (e.g.,
-optimise), though for brevity these are not mentioned below.
-flip horizontalMirror image horizontally (left-right).
-flip verticalMirror image vertically (top-bottom).
-rotate 90Rotate image 90 degrees clockwise.
-rotate 180Rotate image 180 degrees.
-rotate 270Rotate image 270 degrees clockwise (or 90 ccw).
The transpose transformation has no restrictions regarding image dimensions. The other transformations operate rather oddly if the image dimensions are not a multiple of the iMCU size (usually 8 or 16 pixels), because they can only transform complete blocks of DCT coefficient data in the desired way. The other transforms can be built up as sequences of transpose and flip operations; for consistency, their actions on edge pixels are defined to be the same as the end result of the corresponding transpose-and-flip sequence.
exiftran is a command line utility to transform digital image jpeg
images. It can do lossless rotations like jpegtran, but unlike
jpegtran it cares about the EXIF data: It can rotate images automatically by checking the
exif orientation tag, it updates the
exif information if needed (image dimension, orientation), it also rotates the
exif thumbnail. It can process multiple images at once.
-aautomatic (using exif orientation tag)
-9rotate by 90 degrees clockwise
-1rotate by 180 degrees clockwise
-2rotate by 270 degrees clockwise
-ntdon't rotate exif thumbnail.
-nidon't rotate jpeg image. (e.g., you might need this or or the
-ntoption to fixup things in case you rotated the image with some utility which ignores the exif thumbnail. Just generating a new thumbnail with -g is another way to fix it.
-noDon't update the orientation tag. By default
exiftransets the orientation to
"1" (no transformation needed)to avoid other
exif-awareapplications try to rotate the already-rotated image again.
To autorotate all jpeg files in the current directory:
exiftran -ai *.jpeg
View or Post Comments