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 Grid Effect: The top-left corner remains the top-left corner, but the rows of the image become columns, and the columns become rows.
- Result: This creates a mirrored reflection across the diagonal axis running from the top-left to the bottom-right.
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.jpgIf you are using an older version of ImageMagick (version 6 or
below), the syntax utilizes the explicit convert
command:
convert input.jpg -transpose output.jpgTranspose 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.jpgCombining 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