How to Transpose an Image with ImageMagick?

The ImageMagick convert command allows you to easily transpose an image, which flips it both horizontally and vertically by reflecting the pixels across the main diagonal. This article provides a quick overview of how the -transpose operator works, details the exact command syntax needed for execution, and compares it to similar geometric transformations like rotation and transverse flipping. By the end of this guide, you will be able to efficiently manipulate image orientations directly from your command line.

Understanding the Transpose Operation

Transposing an image is a specific geometric transformation. It is equivalent to rotating the image 90 degrees clockwise and then flipping it horizontally.

The Basic Command Syntax

To transpose an image using ImageMagick, you use the magick command (or convert in older versions) followed by the -transpose tool.

magick input.jpg -transpose output.jpg

If you are using an older version of ImageMagick (version 6 or below), the syntax utilizes the explicit convert command:

convert input.jpg -transpose output.jpg

Transpose vs. Transverse

It is easy to confuse transposing with transversing, but they handle different axes:

Operation Axis of Reflection Equivalent Result
-transpose Main diagonal (Top-Left to Bottom-Right) Rotate 90° clockwise + Horizontal flip
-transverse Minor diagonal (Top-Right to Bottom-Left) Rotate 90° clockwise + Vertical flip

If you want to reflect the image across the opposite diagonal, you would substitute the command like this:

magick input.jpg -transverse output.jpg

Combining Operations

You can combine the transpose command with other ImageMagick options, such as resizing or changing formats, all within a single execution block. For example, to transpose an image and resize it to a width of 800 pixels, you can run:

magick input.png -transpose -resize 800x output.jpg