Trim with limitations

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
novito
Posts: 30
Joined: 2013-11-26T17:37:36-07:00
Authentication code: 6789

Trim with limitations

Post by novito »

Hi guys,

I am using the trim function in order to get rid of a background surrounding a product image. However, the trimming sometimes cut too much, and I would like to know if there is a way of giving trim the option to say, give 2px of margin from wherever you were gonna cut to.

I haven't been able to found that on the docs, so I thought you guys could have any ideas.

Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trim with limitations

Post by fmw42 »

You can get the trim bounds by

identify -format "%@" yourimage

put that into a variable or separate into the needed variables. Then add whatever extra you want. Then use -crop WxH+X+Y +repage to crop it with your modified trim variables for W,H,X,Y.

see
http://www.imagemagick.org/script/escape.php
Post Reply