Page 1 of 1

get heigth/width

Posted: 2011-01-05T10:50:53-07:00
by goutosig
Hi all,

I am new to Image Magick and am trying to retrieve the width and height of an image so that I can name it in a different way whether it is a landscape or portrait image.
Here is my code:

Code: Select all

#!/bin/sh
	
for x in `ls originaux`
do

	width=`convert originaux/$x -format "%[fx:w]" info:`
	height=`convert originaux/$x -format "%[fx:h]" info:`

	if [ $height -lt $width ]
	then
		convert originaux/$x -rotate "2" - | convert - -shave 98x119 rotation/pa_$x
	else
		convert originaux/$x -rotate "2" - | convert - -shave 119x98 rotation/po_$x
	fi
done
I do get values for width and height, but the width is always 3456px and height always 2592px whereas my images definitely have different orientations, therefore, some images should be 2592px wide and 3456px high.

Can anyone help me?

G.

Re: get heigth/width

Posted: 2011-01-05T15:19:22-07:00
by fmw42
width=`convert originaux/$x -format "%[fx:w]" info:`
height=`convert originaux/$x -format "%[fx:h]" info:`
This appears to be the correct format and syntax to get the width and height for a given image. It should work. However, you might use miff:- in place of - for the output before the pipe.

Otherwise, check your IM version and be sure you are on a current version and not one that is very old.

If any images have spaces in them, then you should use quotes around the filenames

Re: get heigth/width

Posted: 2011-01-05T17:14:15-07:00
by anthony
Better still use the simplier more direct format %w and %h

Re: get heigth/width

Posted: 2011-01-06T06:18:28-07:00
by goutosig
Hi all,

actually it seems that my IM does not know whether the picture was taken in a landscape or portrait mode; it handles the portrait pictures in a landscape orientation.

Finally, this is not so disturbing to me... though it is strange and I was not able to correct it (I updated from IM 6.6.5 to 6.6.6).

thx for your replies

Re: get heigth/width

Posted: 2011-01-06T06:36:46-07:00
by Bonzo
Out of interest you are rotating the image no mater what oriantation it is ?

Code: Select all

if [ $height -lt $width ]
   then
      convert originaux/$x -rotate "2" - | convert - -shave 98x119 rotation/pa_$x
   else
      convert originaux/$x -rotate "2" - | convert - -shave 119x98 rotation/po_$x

Re: get heigth/width

Posted: 2011-01-11T01:13:47-07:00
by goutosig
Bonzo wrote:Out of interest you are rotating the image no mater what oriantation it is ?

Code: Select all

if [ $height -lt $width ]
   then
      convert originaux/$x -rotate "2" - | convert - -shave 98x119 rotation/pa_$x
   else
      convert originaux/$x -rotate "2" - | convert - -shave 119x98 rotation/po_$x
yes; I finally removed the IF block and kept the first instruction.