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: 45
Joined: 2013-12-13T11:13:29-07:00
Authentication code: 6789

enclose a shape with a rectangle

Post 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!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: enclose a shape with a rectangle

Post 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:
snibgo's IM pages: im.snibgo.com
gubach
Posts: 45
Joined: 2013-12-13T11:13:29-07:00
Authentication code: 6789

Re: enclose a shape with a rectangle

Post 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!
gubach
Posts: 45
Joined: 2013-12-13T11:13:29-07:00
Authentication code: 6789

Re: enclose a shape with a rectangle

Post by gubach »

PerlMagick for

Code: Select all

 convert in.png -format %@ info: 
is

Code: Select all

 $geometry = $in_png->Get('bounding-box'); 
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: enclose a shape with a rectangle

Post by snibgo »

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