Trim too agressive

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
GieltjE
Posts: 2
Joined: 2018-09-07T05:08:10-07:00
Authentication code: 1152

Trim too agressive

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Trim too agressive

Post 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.
snibgo's IM pages: im.snibgo.com
GieltjE
Posts: 2
Joined: 2018-09-07T05:08:10-07:00
Authentication code: 1152

Re: Trim too agressive

Post 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)
Last edited by GieltjE on 2018-09-07T06:32:59-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Trim too agressive

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply