Page 1 of 1

crop image borders based on color

Posted: 2008-09-16T09:29:46-07:00
by romero619
I think this might be impossible to do, but I'll ask anyway...

If I have an image (png) with a border/margin around its edges of unknown width and of a specific color, would it be possible to automatically crop the border based on color?

I.E., I have a 300x300px image, with a flower in the center of a white box/background, and then a 100px black margin all around the edges of the white area. I wouldnt know beforehand how wide the black margin is, so I would need to tell imagemagick "trim off all of the black border, leave just the white box/background with flower....

Is there anything like this available through imageMagick???
Please help, thanks...

Re: crop image borders based on color

Posted: 2008-09-16T09:42:36-07:00
by fmw42
see -trim and -fuzz at http://www.imagemagick.org/script/comma ... ptions.php

convert <image> -trim +repage <result>

convert <image> -fuzz xx% -trim +repage <result>

-fuzz allows the trim to match colors similar to those at the corners

Re: crop image borders based on color

Posted: 2008-09-17T00:25:18-07:00
by anthony
To -trim based on a specific color first add a -border of that color. The -fuzz will then match colors centered on that color.