Removing Black Borders from 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
sameersbn
Posts: 4
Joined: 2011-08-05T06:43:46-07:00
Authentication code: 8675308

Removing Black Borders from Image

Post by sameersbn »

Hi,

I have developed application that uses ffmpeg to generate a thumbnail of a video. If the video has black borders then the black borders are also part of the image. I was wondering if it was possible to clip the black borders from the image using magick. Tried searching on google but could not find anything useful (still looking).

Here is a sample image with black borders
Image

Thanks and Regards
~Sameer
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Removing Black Borders from Image

Post by Bonzo »

sameersbn
Posts: 4
Joined: 2011-08-05T06:43:46-07:00
Authentication code: 8675308

Re: Removing Black Borders from Image

Post by sameersbn »

great! thanks for the info.
i was trying to figure out how -fuzz is specified. the doc says distance but couldn't figure out how it is specified.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Removing Black Borders from Image

Post by Bonzo »

I think fuzz is a percent so it would be something like this:

Code: Select all

convert image_in -fuzz 20% -trim image_out
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Removing Black Borders from Image

Post by fmw42 »

Bonzo wrote:I think fuzz is a percent so it would be something like this:

Code: Select all

convert image_in -fuzz 20% -trim image_out
Don't forget the +repage after the -trim if the output is png or gif or tif and not jpg

see http://www.imagemagick.org/Usage/crop/#trim

P.S. Fuzz values can be absolute graylevel in the range of your compile Q8 (0-255) or Q16 (0-65535), but I find percents easier and more flexible and transportable
sameersbn
Posts: 4
Joined: 2011-08-05T06:43:46-07:00
Authentication code: 8675308

Re: Removing Black Borders from Image

Post by sameersbn »

This is perfect.
Thanks guys.
sameersbn
Posts: 4
Joined: 2011-08-05T06:43:46-07:00
Authentication code: 8675308

Re: Removing Black Borders from Image

Post by sameersbn »

For reference here's the command i am using:

Command:
convert before.jpg -bordercolor black -border 1x1 -fuzz 20% -trim after.jpg

References:
http://www.imagemagick.org/script/comma ... s.php#trim
http://www.imagemagick.org/Usage/crop/#trim

Regards
~Sameer
Post Reply