How to find out if a *.jpg is currently rotated?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
bensto
Posts: 31
Joined: 2012-07-02T00:32:10-07:00
Authentication code: 13

How to find out if a *.jpg is currently rotated?

Post by bensto »

Many cameras create a photo file with originally portrait orientation by
capturing it pyhsically in landscape mode and create header tag that it is rotated by 90 (or 270 deg).

When such a *.jpg file is opened in a (most) picture viewer, then the picture viewer reads at first the orientation header tag and displays the photo in correct view.

Now, how can I read with ImageMagick from (DOS batch) script file the orientation value from *.jpg header?

Later I want to implement something like

set orient = convert -showorientation mysample.jpg
if orient=90 (jpegtran -rotate 270 mysample.jpg mysampleout.jpg)

In other words: I want to convert the virtual orientation into a physical one.

What I need is the ImageMagick command to get the orientation angle from Jpg header.

Thank you
Ben
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to find out if a *.jpg is currently rotated?

Post by fmw42 »

ImageMagick will auto-orient your image for you when you read it. See -auto-orient at https://imagemagick.org/script/command- ... uto-orient.

You can get the orientation flag from the head using -format "%[EXIF:orientation]" info:, if it exists in the header. See % escapes at https://imagemagick.org/script/escape.php. There are tables that correspond the flags with the orientation/rotation. See https://www.impulseadventure.com/photo/ ... ation.html and https://magnushoff.com/jpeg-orientation.html or search Google.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to find out if a *.jpg is currently rotated?

Post by snibgo »

What version of IM, on what platform?

See "orientation" on http://www.imagemagick.org/script/escape.php

Code: Select all

magick or_1.jpg -format %[orientation] info:

TopLeft
See also http://www.imagemagick.org/script/comma ... uto-orient and Orientation.
snibgo's IM pages: im.snibgo.com
Post Reply