Page 1 of 1

enclose a shape with a rectangle

Posted: 2015-03-17T11:15:26-07:00
by gubach
I have a white shape over a black background and I want the coordinates of the two points that define the smallest rectangle that encloses the given shape. To get those values I have to compute the distance from the left boarder to the shape and from the top boarder to the shape. Has someone PerlMagick code for this? Thank you very much!

Re: enclose a shape with a rectangle

Posted: 2015-03-17T20:00:46-07:00
by snibgo
I don't know Perl. From the command line, you can get the rectangle's width and height, and top-left corner, from:

Code: Select all

convert in.png -format %@ info:

Re: enclose a shape with a rectangle

Posted: 2015-03-19T06:54:10-07:00
by gubach
snibgo wrote:I don't know Perl. From the command line, you can get the rectangle's width and height, and top-left corner, from:

Code: Select all

convert in.png -format %@ info:
thank you!! This helps for now!

Re: enclose a shape with a rectangle

Posted: 2015-03-24T15:10:41-07:00
by gubach
PerlMagick for

Code: Select all

 convert in.png -format %@ info: 
is

Code: Select all

 $geometry = $in_png->Get('bounding-box'); 

Re: enclose a shape with a rectangle

Posted: 2015-03-24T15:23:39-07:00
by snibgo
Thanks for posting the answer.