Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageMagick - Remove black borders

I have about 100 scanned pictures (.jpg), all with black borders (top/right/bottom/left), like this:

input.jpg

I want to trim my picture automatically, that it is without ANY black border.

I tried different codes, the best result I get with this code (I use Imagemagick Version 7.0.7-Q16 for Windows):

magick mogrify -bordercolor black -fuzz 20% -trim -format jpg *.jpg

It generates this picture:

result with my code

Which is a good start, but as you can still see there is a rest of the black border on the top, right, bottom and left side of the image and two black areas in the sky .

I want that the picture looks like this:

wish result

How can I do this?

Any help or hint for my problem will be appreciated! Thanks in advance!

like image 211
SueSchi Avatar asked Sep 03 '26 05:09

SueSchi


1 Answers

You cannot always get rid of all the black background by that command alone, especially if the image is slightly rotated. You may need to shave some off all around, but there is no easy way to know by how much. Also the background color you specify has no effect in your ImageMagick trim command.

Try

magick mogrify -fuzz 20% -trim +repage -shave 7x7 -format jpg *.jpg

Adjust the shave amounts as desired.

like image 159
fmw42 Avatar answered Sep 04 '26 20:09

fmw42



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!