Trim canvas to only fit image?

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
vbsaltydog

Trim canvas to only fit image?

Post by vbsaltydog »

I have a series of images, each one sits on a 300x300 white background and are centered on the x and y axis.
I need to trim down the white background or "canvas" so that it is cropped tightly around the image ... say 10px padding.

The problem is that all of the images on the backgrounds are different sizes in regard to width and height so I can't pass coordinates to the crop command. Is there a way to auto detect where the image is on the background canvas and then autocrop around the image?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trim canvas to only fit image?

Post by fmw42 »

vbsaltydog

Re: Trim canvas to only fit image?

Post by vbsaltydog »

Thank you. Trim worked perfetly. I thought it would only remove borders of colors dissimilar from the background.

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

Re: Trim canvas to only fit image?

Post by fmw42 »

if you add -fuzz somevalue% -trim then it will trim using fuzzy values, i.e. the color does not have to be exact
Post Reply