Page 1 of 1

Draw rectangle w/relative positions rather than absolute?

Posted: 2008-05-06T15:55:31-07:00
by stevepugh
Hi all,

I would like to load an image from disk and draw a rounded rectangle using 40% of the image's width and 40% of the image's height as the upper left corner and 70% of the width, 70% height as the lower right corner of the rectangle.

How would I accomplish this? From what I can read in the usage docs, -draw needs pixel coordinates and these strike me as absolute.

Many thanks, and sorry if this is...lame.

Best,
Steve

Re: Draw rectangle w/relative positions rather than absolute?

Posted: 2008-05-06T18:57:57-07:00
by fmw42
ulx=`convert xc: -format "%[fx:40*w/100]" info:`
uly=`convert xc: -format "%[fx:40*h/100]" info:`
brx=`convert xc: -format "%[fx:70*w/100]" info:`
bry=`convert xc: -format "%[fx:70*h/100]" info:`

feed these to -draw "roundrectangle $ulx,$uly $brx,$bry ...."

see fx escapes
http://www.imagemagick.org/Usage/transform/#fx_escapes

Re: Draw rectangle w/relative positions rather than absolute?

Posted: 2008-05-06T20:50:18-07:00
by stevepugh
Wow, just a cursory glance at that link and my eyes are bleeding. I've got to put a pot of coffee on and start digging! Considering that a contact sheet 'montage' operation is as hardcore as I've gotten so far with IM, this is a bit of a jump for me.

To complicate matters, I'm on a WindowsXP box and am frankly not sure that it's got the mad scripting capabilities of bash/perl. I shudder at the thought. Ought this still be doable, ya think?

Many thanks,
Steve

Re: Draw rectangle w/relative positions rather than absolute?

Posted: 2008-05-06T22:03:09-07:00
by fmw42
The computations of the coordinates for the UL and BR are done using only IM commands (fx escape calculations).
They simple use -fx to get the width (w) or the height (h) and scale by 40/100=40% or 70% and put those in variables that can be used in -draw for the coordinates.

They are not bash scripting computations such as the use of bc or expr. So they should work in Windows. However, there are some Windows considerations you should review. See

http://www.imagemagick.org/Usage/api/#windows