How to Rotate an Image 90 Degrees in ImageMagick?

Rotating an image by 90 degrees using ImageMagick’s convert command is a straightforward process achieved by using the -rotate operator followed by the desired angle. This article provides a quick overview of the basic command syntax for clockwise and counterclockwise rotations, explains how to handle image orientation metadata, and demonstrates how to batch process multiple images at once.

The Basic Rotation Command

To rotate a single image, you specify the input file, the -rotate flag with the degrees of rotation, and the name of the output file. ImageMagick accepts positive numbers for clockwise rotation and negative numbers for counterclockwise rotation.

Handling Backgrounds and Metadata

When rotating images that are not perfectly square, or when rotating by angles other than 90-degree increments, ImageMagick will fill the empty corner space with a default background color (usually white). For exact 90-degree rotations of rectangular images, the dimensions simply swap (e.g., a 1920x1080 image becomes 1080x1920) without creating empty corner space.

Resetting Exif Orientation Tags

Many modern digital cameras and smartphones do not actually rotate the pixels when you take a photo vertically; instead, they write an “Orientation” tag into the Exif metadata. If you manually rotate an image that already contains this tag, some image viewers might display it incorrectly. To fix this, you can strip the profile metadata or use the -auto-orient command first.

convert input.jpg -auto-orient -rotate 90 output.jpg

Batch Processing Multiple Images

If you have an entire folder of images that need a 90-degree rotation, doing them one by one is inefficient. You can use a simple terminal loop to process them all simultaneously.

On Linux and macOS (Bash/Zsh)

for img in *.jpg; do
    convert "$img" -rotate 90 "rotated_$img"
done

On Windows (Command Prompt)

for %i in (*.jpg) do convert "%i" -rotate 90 "rotated_%i"

Using the Modern Magick Syntax

In newer versions of ImageMagick (ImageMagick 7 and above), the convert command is deprecated in favor of the unified magick command. The syntax remains exactly the same, requiring only a swap of the primary keyword:

magick input.jpg -rotate 90 output.jpg