enclose a shape with a rectangle

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
gubach
Posts: 37
Joined: 2013-12-13T11:13:29-07:00
Authentication code: 6789

enclose a shape with a rectangle

Post by gubach » 2015-03-17T11:15:26-07:00

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!

snibgo
Posts: 11712
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: enclose a shape with a rectangle

Post by snibgo » 2015-03-17T20:00:46-07:00

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:
snibgo's IM pages: im.snibgo.com

gubach
Posts: 37
Joined: 2013-12-13T11:13:29-07:00
Authentication code: 6789

Re: enclose a shape with a rectangle

Post by gubach » 2015-03-19T06:54:10-07:00

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!

gubach
Posts: 37
Joined: 2013-12-13T11:13:29-07:00
Authentication code: 6789

Re: enclose a shape with a rectangle

Post by gubach » 2015-03-24T15:10:41-07:00

PerlMagick for

Code: Select all

 convert in.png -format %@ info: 
is

Code: Select all

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

snibgo
Posts: 11712
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: enclose a shape with a rectangle

Post by snibgo » 2015-03-24T15:23:39-07:00

Thanks for posting the answer.
snibgo's IM pages: im.snibgo.com

Post Reply