Trim in all 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
zorrua
Posts: 1
Joined: 2018-09-03T13:55:34-07:00
Authentication code: 1152

Trim in all borders

Post by zorrua » 2018-09-03T14:06:38-07:00

Hello all,

I am new here, hope I stay for a long.

I have scanned hundres of old photos, the problem is that all of them have borders I want to crop all of them. Here is an example:

Image

I use this command to delete automatically in batch mode:

Code: Select all

mogrify -fuzz 50% -trim +repage *.*
It works well:

Image

But the problem is that I execute the command 3 times to delete all margins, and I get problems with some photos.

How could select the side (left, right, top, botton) of the border I want to delete? I want to use different fuzz value in each execution.

Is there any other command I could use?

I will really appreciate your help.

Kind regards.

User avatar
fmw42
Posts: 24125
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trim in all borders

Post by fmw42 » 2018-09-03T16:22:31-07:00

Just repeat your command as many time as you want changing the fuzz value as desired. Best to add 1 pixel border of the correct color about the image before trimming.

But your image does not have a straight edge at the top. So you get some white at the top left, which prevents the black from being trimmed. You could shave or chop to remove some small amount before doing the next trim.

try

Code: Select all

mogrify -shave 10x10 -bordercolor gray -border 1 -fuzz 20% -trim +repage -bordercolor black -border 1 -fuzz 20% -trim +repage *

Post Reply