I'm not a big AI slop user, but I've always had bad luck at learning ImageMagick from StackOverflow posts etc., so I asked GPT-4o mini (via Duck.ai) how to check if cropping needs to be done before actually running `mogrify`. It told me that a `convert -trim ... -format '%wx%h' info:` would simulate the trimming and output the size without writing to disk, and suggested using `identify` to compare to the original size. Running three ImageMagick commands instead of one feels like it can't be the most efficient way, but it seems to work.
So my trimming script actually does the
>`mogrify -bordercolor black -trim "${img}"`
only if the trimmed size as reported by
>`convert -bordercolor black -border 1 -trim "${img}" -format '%wx%h' info:`
and the original image size reported by
>`identify -ping -format '%wx%h' "${img}"`
don't match. That last thing will tend to be my screen resolution unless I'm running a game in windowed mode which I rarely do, but whatever; `identify` is fast. Meanwhile, although `convert` is generally just `mogrify` but to a new file, the `convert ... info:` command to predict the trimmed size is sufficiently faster than `mogrify` that I'm satisfied it's not doing double work (or maybe it's only that much faster because the file writing is skipped but whatever).
For now (although I should come up with a better solution for this), I also skip the `mogrify` if the predicted trimmed size is neither 1920x1080 or 1600x1200, because those are the only valid results for the use cases I have right now. This makes it not attempt to trim screenshots where I've left the MangoHud overlay hanging into the black area, so the attached screenshot was left alone. Otherwise it would have been trimmed to 1750x1200 which would look weird and stupid.
By the way, I know markdown doesn't work on 4chan, but I'm used to putting code between backticks and I refuse to stop.