Page 1 of 1

Trim too agressive

Posted: 2018-09-07T05:26:47-07:00
by GieltjE
Using: ImageMagick-6.9.10-11-Q16-x64-dll.exe, windows 10-1803

Using multiple command's I haven't been able to keep the trim command from trimming the bottom yellow bar (a "hard" trim on absolute white suffices for my use case).

Unfruitful attempts:

Code: Select all

convert imagemagick-input.jpg -trim imagemagick-result.jpg

Code: Select all

convert imagemagick-input.jpg -background white -fuzz 0% -trim imagemagick-result.jpg
Workaround (not really a neat solution in my opinion)

Code: Select all

convert imagemagick-input.jpg -background white -splice 5x0 -fuzz 0% -trim imagemagick-result.jpg
Input:
Image

Result (expecting nothing to have changed as it was properly trimmed to begin with):
Image

Re: Trim too agressive

Posted: 2018-09-07T06:05:26-07:00
by snibgo
The bottom edge is the same colour as the bottom two corner pixels, so "-trim" removes it. See http://www.imagemagick.org/script/comma ... s.php#trim

To avoid this, a common trick is to add a one-pixel white border before trimming.

Re: Trim too agressive

Posted: 2018-09-07T06:24:51-07:00
by GieltjE
Thanks, didn't get the part about it using the bottom two corner pixels, is there a way to make it look at other pixels/a forced color? (simply adding a border with a chosen color works for now)

Re: Trim too agressive

Posted: 2018-09-07T06:32:47-07:00
by snibgo
It looks at all four corners.

Another way to describe the action is: if any of the four edges contain the same colour, those edges will be removed. If an image has rows of white pixels at the top edge and yellow at the bottom edge, the top will be trimmed down to the first non-white and the bottom will be trimmed up to the first non-yellow.

If you want to ensure that only white pixels are removed, add a white border first.