-Trim of uneven black borders

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
Aleg-One
Posts: 2
Joined: 2014-10-17T01:59:38-07:00
Authentication code: 6789

-Trim of uneven black borders

Post by Aleg-One »

Hello ImageMagick board!

I have researched the different batch editing tools out there, and have come to the conclusion that ImageMagick seems like the choice for my needs.

The work I need to have done, is to batch-convert about 100.000 .tiff pictures (old documents, about 20mb each) that have been scanned with a (not evenly/solid) black border around it. It's not a consistent border, sometimes it's only top-bottom-right, sometimes only top-bottom and so on. so a crop function wouldn't suffice. So I need a function that detects this black border and auto-crops the entire batch - if it's possible!

Any pointers to which direction an ImageMagick noob like myself should look at?

It would be very much appreciated :)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -Trim of uneven black borders

Post by snibgo »

By coincidence, I've started a job on old documents today.

For your border problem, I usually add a black border of 1 pixel all the way round, then trim the black border, eg:

Code: Select all

convert in.png -bordercolor Black -border 1 -fuzz 5% -trim out.png
The fuzz factor allows for the border not being exactly black. Adjust to suit, or remove it if the border is exactly black.
snibgo's IM pages: im.snibgo.com
Aleg-One
Posts: 2
Joined: 2014-10-17T01:59:38-07:00
Authentication code: 6789

Re: -Trim of uneven black borders

Post by Aleg-One »

Thank you, it worked like a charm! :) had to set the fuzz to about 30% though :)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -Trim of uneven black borders

Post by snibgo »

Good stuff. I should have said: you probably want "+repage" before the output filename. See http://imagemagick.org/script/command-l ... php#repage

Code: Select all

convert in.png -bordercolor Black -border 1 -fuzz 5% -trim +repage out.png
snibgo's IM pages: im.snibgo.com
Post Reply