Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
480 views
in Technique[技术] by (71.8m points)

imagemagick - How can I display the orientation of a JPEG file?

What ImageMagick command will display the orientation of a JPG file?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

Affect of Orientation Metadata

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).

  1. identify -format '%[EXIF:orientation]' <InputFileName> [To get exact metadata value.]
  2. 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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...