Page 1 of 1
Using aspect-ratio orientation to select bg image
Posted: 2011-07-26T13:09:37-07:00
by motumbo
I have to use the aspect-ratio orientation (portrait vs landscape) of an image to dynamically select between two backgrounds. I have to use the 'convert' tool.
ie if width > height (of my_photo.jpg) use bg_1.png as background and if width <= height (of my_photo.jpg) use bg_2.png as background.
Re: Using aspect-ratio orientation to select bg image
Posted: 2011-07-26T15:05:49-07:00
by fmw42
What version of IM are you using and on what platform?
If on Unix-- linux/mac, then
aspect=`convert image -format "%[fx:w/h>1?1:0]" info:`
if [ $aspect -eq 1 ]; then
# process for landscape
else
# process for portrait
fi
If on windows, the syntax will be different. I am not a windows user, so see
http://www.imagemagick.org/Usage/windows/
Re: Using aspect-ratio orientation to select bg image
Posted: 2011-07-26T16:29:59-07:00
by motumbo
Linux ImageMagick 6.5.4-7 2011-01-17
I was wondering if I can accomplish this with a single call (I'm using PHP), right now I'm using this:
convert bg_1.png ( my_photo.jpg -thumbnail 600x600 ) -geometry +200+120 -compose Multiply -composite output.jpg
maybe combining:
-set filename:aspect '%[fx:w/h>1?1:0]'
and
'bg_%[filename:aspect].png'
Re: Using aspect-ratio orientation to select bg image
Posted: 2011-07-26T18:45:21-07:00
by fmw42
[ `convert image -format "%[fx:w/h>1?1:0]" info:` -eq 1 ] && # process for landscape || # process for portrait
Re: Using aspect-ratio orientation to select bg image
Posted: 2011-07-26T18:54:21-07:00
by anthony
Code: Select all
bg=bg_1.png ;
[ `convert image.png -format "%[fx:w/h>1?1:0]" info:` -eq 1 ] && bg=bg_2.png ;
convert image.png $bg ....do your process.... output.png
Just put it all in the 'string to be executed in PHP. The PHP exec() function calls a shell which can process multiple shell commands, or even a small shell script!
Re: Using aspect-ratio orientation to select bg image
Posted: 2011-07-27T11:01:06-07:00
by motumbo
Thanks!
Re: Using aspect-ratio orientation to select bg image
Posted: 2011-08-25T04:22:05-07:00
by michelle
*perfect*, thanks Fred - this really helped me ammend my overly complex, convaluted attempt. Thank-you.
C:\tmp>convert landscape.tif -format "%[fx:w/h>1?1:0]" info:
1
C:\tmp>convert portrait.pdf -format "%[fx:w/h>1?1:0]" info:
0
C:\tmp>convert portrait.pdf -rotate 90 was-portrait__now-landscape.png
michelle