What ImageMagick command will display the orientation of a JPG file?
The length of the longest side determines the orientation. For example, if the height of the image is longer than the width, it is a “portrait” format. Images where the width is longer are called “landscape.”
Right-click the image and select Details to reveal a screen with metadata, including EXIF data, that you can adjust if the image supports it. Force a preferred orientation. Rotate the image, then save it. That process reconstructs the image along the requested dimensions.
IrfanView. IrfanView is a great image viewer on Windows, which respects the image Exif info. To view the image Exif info, open an image and click Image -> Information . If the image contains Exif info, you can then click the EXIF info button at the bottom left of the popup window to check the image Exif info.
Introduction
Images stores more than just pixel information. A lot of information is stored in form of metadata. Images can have multiple metadata in multiple metadata directories. Some examples are: Exif, IPTC, JFIF, Ducky, etc.
Orientation is one of such metadata tag in Exif directory. This metadata informs your display devices on how to orient an Image after decoding the pixel data. This metadata has valid values from 1-8. This metadata is not always present in Images, as one can remove the metadata from images. It is also possible to set this metadata to wrong values such as 0, 9, 17, etc, since this metadata supports 16-bit unsigned values(0-65535).
The image below shows how display of image is affected using this metadata. Image source: https://me94.me/2316.html
Imagemagick Solution
Fetching orientation from Imagemagick(IM) can mean two things. You might be (mostly) interested in fetching what orientation the image has, and the second would be to know the exact value of orientation metadata tag(in rare cases, I assume).
To know the orientation, you thus have two IM commands(small variation in what they output).
identify -format '%[EXIF:orientation]' <InputFileName>
[To get exact metadata value.]identify -format '%[orientation]' <InputFileName>
[To get image orientation value, a mapping of exif value to readable term.]For command 1:-
The output is the exact value even when value may not be valid. For example:- 0,1,5 or even 65535. However, in the absence of this metadata, the output(IMHO ambiguous output) is: identify: unknown image property "%[EXIF:orientation]" @ warning/property.c/ InterpretImageProperties/3785.
For command 2:-
The output is as following:-
Undefined - 0 Undefined - [When no metadata] TopLeft - 1 TopRight - 2 BottomRight - 3 BottomLeft - 4 LeftTop - 5 RightTop - 6 RightBottom - 7 LeftBottom - 8 Unrecognized - any value between 9-65535, since there is no mapping from value 9-65535 to some geometry like 'LeftBottom'
Tested on Mac and Ubuntu(EC2)
You can use
identify -format '%[EXIF:Orientation]' <image.jpg>
as per identify -format
docs (It's the bit further down about exif metadata).
Try
identify -verbose <image.jpg>
To see what metadata is in the image (for example if the image was not taken with a camera, the orientation tag will not be set).
Alternatively you could do something like
identify -format '%wx%h' <image.jpg>
which gives you the width by height (e.g. '800x598', '1936x2592') and use these to determine whether the image is upright or not (not sure how reliable this is though - sometimes you take a portrait image with a camera and the EXIF data will correctly record the orientation, but the image may still appear landscape).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With