How to rotate a JPEG without losing quality (and many photos at once)

Rotate a photo in a basic editor, save, and the file is quietly re-compressed. Do that a few times and the blocky artefacts add up. A JPEG can be turned with no loss at all, though, if you choose the right method.

Why ordinary rotation loses quality

JPEG stores a picture as 8×8 (or 16×16) blocks of compressed detail. An editor that rotates a photo usually decodes it to plain pixels, turns them, and compresses the result again. That second compression throws away a little more detail. One pass at a high quality setting is barely visible; repeated passes, or a low quality setting, are.

Three ways to turn a JPEG

MethodQualityWorks everywhere?Hidden data
Change the Orientation tagIdentical (pixels untouched)Most modern apps and browsers; some older software and sites ignore itKept, including GPS
Lossless transform (jpegtran, some viewers)Identical, except a thin edge strip when the size is not a multiple of 8 or 16YesDepends on the tool's options
Redraw and re-saveA tiny loss at quality 90+YesUsually dropped

What the Orientation tag is

Most phones and cameras do not physically turn the picture when you hold them sideways. They save the pixels the way the sensor saw them and write a number from 1 to 8 into the EXIF data: 1 means “as is”, 6 means “turn right 90°”, 3 means “180°”, 8 means “turn left 90°”, and 2, 4, 5 and 7 add a mirror. A viewer reads the number and turns the picture as it draws it. Changing that number is enough to turn the photo, and it takes two bytes.

The catch: if a tag is already there, the new value has to combine your turn with the camera's. Setting “turn right” on a photo whose camera tag already said “turn right” would leave it upside down. The rotator works this out for you, starting from what you actually see in the preview.

Turning a batch, losslessly, in the browser

  1. Open the batch photo rotator and drop the photos in (up to 50). Nothing is uploaded.
  2. Give each one the turn it needs. Each has its own Undo, and Ctrl+Z steps back through recent changes.
  3. Under How to turn JPEGs, pick Lossless, then Download copies. Each JPEG keeps its exact bytes except for the tag. PNG and WebP are redrawn, because they have no widely supported equivalent.

Lossless keeps everything else in the file, including GPS location. If you are posting the photos publicly, choose Redraw the picture instead, which leaves the location behind (see how to remove GPS from a photo).

On the command line

# change only the tag (exiftool): 6 = turn right
exiftool -n -Orientation=6 -overwrite_original photo.jpg

# true lossless transform of the pixels, then clear the tag
jpegtran -copy all -rotate 90 -perfect photo.jpg > turned.jpg
exiftool -n -Orientation=1 -overwrite_original turned.jpg

-perfect makes jpegtran refuse rather than trim an edge when the width or height is not a multiple of the block size. Work on copies: -overwrite_original means exactly that.

Related

Put photos in order and number them · Photo sideways in Word, Outlook or email · Batch photo rotator (in your browser) · Why a photo turns sideways after upload · Remove GPS from a photo · Compress many photos at once

Questions

Does rotating a JPEG reduce its quality?

It does if the editor re-saves the picture, which most simple editors do. Changing only the Orientation tag, or using a lossless transform such as jpegtran, leaves the image data untouched.

Is changing the orientation tag safe?

Yes. It is the same tag your camera wrote. The only drawback is that a few older programs and some websites ignore it and will show the original sideways pixels.

Why did my photo end up upside down after I rotated it?

The photo probably already had an orientation tag, and the tool you used added its turn without counting the existing one, or rotated the pixels and kept the old tag. Check what you see in a preview, and use a tool that combines the two.

Can I rotate many photos at once without losing quality?

Yes. The batch photo rotator's Lossless mode sets the tag for every JPEG in the batch and gives you one ZIP, all in your browser.

Published · updated .

Try it

Related guides

Newest guides