Page 1 of 1

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

Posted: 2019-06-25T14:22:58-07:00
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

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

Posted: 2019-06-25T14:44:16-07:00
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.

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

Posted: 2019-06-25T14:49:55-07:00
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.