I have an image. I need to crop the rectangle region from the image. This rectangle region is identified by black color border. Inside the rectangle is what I need. Is it possible to crop the black color bordered rectangle region in imagemagick? I know it could be possible using crop command by providing offset(-crop WxH+X+Y) of the rectangle region. But I want to crop the rectangle region without manually measuring the upper left and lower right corners of the rectangle. Is it possible to crop the rectangle region using black color border alone...???
How about something like this?
convert source.jpg -fuzz 10% -bordercolor black -border 1x1 -trim +repage dest.jpg
You may have to play around with the 'fuzz' percentage. The reason you need the fuzz option is that without it trim will only trim pixels that are exactly black - with JPEGs this is unlikely to be the case.
All this is explained on this page: http://www.imagemagick.org/Usage/crop/#trim
This solution will only work if the black border goes right up to the edges of the image. If this is not the case then I don't think you'll be able to do what you need to with IM without examining the image (e.g. pixel by pixel) programmatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With