Getting correct image width and height

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
Masejoer
Posts: 23
Joined: 2016-06-23T11:34:37-07:00
Authentication code: 1151

Getting correct image width and height

Post by Masejoer »

Another topic - I'm having issues getting consistent width and height values using "convert -format". I've noticed that the same image on Windows 7, Windows 10, and Ubuntu reports different widths and heights. One environment may report portrait dimensions while another reports landscape dimensions. When I view a bunch of images in a web browser, they are always in landscape mode, but many times IM is giving me portrait dimensions. Is there a consistent way to get width and height from an image, with images generated from a variety of devices?

I'm running ImageMagick-7.0.1-6 Q16-x64 on Windows (.bat) and 7.0.2-5 Q16-x64 on Ubuntu (.sh).

Code: Select all

convert input.jpg -format "%w %h" info:
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Getting correct image width and height

Post by snibgo »

Masejoer wrote:I've noticed that the same image on Windows 7, Windows 10, and Ubuntu reports different widths and heights.
Please supply an example file that has this problem.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Getting correct image width and height

Post by fmw42 »

Also how did you determine the heights? What IM command?
Masejoer
Posts: 23
Joined: 2016-06-23T11:34:37-07:00
Authentication code: 1151

Re: Getting correct image width and height

Post by Masejoer »

snibgo wrote:
Masejoer wrote:I've noticed that the same image on Windows 7, Windows 10, and Ubuntu reports different widths and heights.
Please supply an example file that has this problem.
Got a new photo. I had to get one without identifying information.

This was taken with an iPhone. It shows different orientation in different environments. Because of this, sometimes IM shows portrait data while a PC and web browser shows landscape, and vice versa.

http://www.masejoer.com/Images/IM/B3B9E ... BC4E21.jpg
Masejoer
Posts: 23
Joined: 2016-06-23T11:34:37-07:00
Authentication code: 1151

Re: Getting correct image width and height

Post by Masejoer »

fmw42 wrote:Also how did you determine the heights? What IM command?

Code: Select all

read -r WW HH <<< $( convert ./input.jpg -format "%w %h" info:) `#Get width and height of image` 
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Getting correct image width and height

Post by snibgo »

The image is wider than it is tall. IM should always say this. Does it ever say anything else?

The image also has metadata that says "display this rotated 90 degrees clockwise". Some software obeys this; some doesn't.
snibgo's IM pages: im.snibgo.com
Post Reply