`-define trim:minSize` malfunctioning
Author: q3cpmaCreated Aug 28, 2026Updated Aug 29, 2026
ImageMagick version
7.1.2-18
Operating system
Linux
Operating system, version and so on
Gentoo
Description
That setting is basically pure chaos here, it seems to somehow influence the trimmed sized but in unpredictable ways (and -gravity too). And while only some height is being trimmed, the width part of the geometry actually modifies the result too.
cf reproduction steps
Without seeing the code but extrapolating from 3 and 4, the formula here is something like "(required height - fully cropped height) / 2" because of the -gravity or something.
Steps to Reproduce
$ magick -verbose test.png -gravity center -trim +repage test_trimmed.png 2>&1 | tail -n1
test.png=>test_trimmed.png PNG 600x500=>600x446 8-bit TrueColor sRGB 81530B 0.040u 0:00.046
$ magick -verbose test.png -define trim:minSize=600x450 -gravity center -trim +repage test_trimmed.png 2>&1 | tail -n1
test.png=>test_trimmed.png PNG 600x500=>600x446 8-bit TrueColor sRGB 81530B 0.050u 0:00.049
$ magick -verbose test.png -define trim:minSize=x450 -gravity center -trim +repage test_trimmed.png 2>&1 | tail -n1
test.png=>test_trimmed.png PNG 600x500=>600x446 8-bit TrueColor sRGB 81530B 0.040u 0:00.046
$ magick -verbose test.png -define trim:minSize=601x450 -gravity center -trim +repage test_trimmed.png 2>&1 | tail -n1
test.png=>test_trimmed.png PNG 600x500=>600x448 8-bit TrueColor sRGB 81530B 0.050u 0:00.046
$ magick -verbose test.png -define trim:minSize=601x460 -gravity center -trim +repage test_trimmed.png 2>&1 | tail -n1
test.png=>test_trimmed.png PNG 600x500=>600x453 8-bit TrueColor sRGB 81530B 0.040u 0:00.046As you can see from the attempts:
- Unrestrained case: it only chops off some height (top, actually).
- Try to restrain the output height with
600x450andx450, to no avail. 601x450somehow does something by leaving 2 pixels off.- Same with
601x460, which leave 7 pixels off.
Images
The test.png in question:
Source: ImageMagick/ImageMagick