In a script,  you can compute the aspect ratio (w/h) to determine 
which is longer

aspect=`convert yourimage -format "%[fx:w/h]" info:`
test=`echo "$aspect > 1" | bc `
[ $test -eq 1 ] && echo "width is longer than height" || echo "height 
is longer than width"

or you can use the test with the actual image width and heights to 
figure out the width or height to crop to make it 4:3 aspect  (you 
can use this to center crop or crop from any of the corners using 
-gravity, but if you use -crop be sure to end with +repage)

infile="yourimage"
width=`convert $infile -format "%w" info:`
height=`convert $infile -format "%h" info:`
aspect=`convert $infile -format "%[fx:w/h]" info:`
test1=`echo "$aspect > 4/3" | bc `
test2=`echo "$aspect > 1 && $aspect < 4/3" | bc`
test3=`echo "$aspect < 3/4" | bc`
test4=`echo "$aspect < 1 && $aspect > 3/4" | bc`
if [ $test1 -eq 1 ]; then
newwidth=`convert xc: -format "%[fx:(4/3)*$height]" info:`
elif [ $test2 -eq 1 ]; then
newheight=`convert xc: -format "%[fx:(3/4)*$width]" info:`
elif [ $test3 -eq 1 ]; then
newheight=`convert xc: -format "%[fx:(4/3)*$width]" info:`
elif [ $test2 -eq 1 ]; then
newwidth=`convert xc: -format "%[fx:(3/4)*$height]" info:`
fi

Note you have to be careful how you handle the case where the aspect 
ratio is less than 4/3 but greater than 1 and similarly for the other 
dimension.



>I have few 1000s APS film scanned images at (variously) 1872x3328 &
>3328x1872 and I want to make a selection of a few 100s of them and prepare
>these for loading onto a 800x600 digital picture frame as a gift.
>
>What (I think) I need to do is:
>1) remove the (~90pixel) white frame around the APS scanned image (convert
>-crop); then:
>2) cut off wider margins at each end of the long sides to be left with 4:3
>image (convert -crop again); then:
>3) shrink the remainder to fit (convert -resize x600)
>
>What worries me is step 2). How do I crop the ends off the long sides
>without first knowing the orientation of the picture? (I guess I could
>sort them into two separate directory before conversion, but ...)
>
>Has anyone done something like this before? If you could help me with
>hints for the convert command line args, I'd be most grateful.
>
>Best regards, Ralph.
_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users

Reply via email to