How do I get the offset result from "-trim"?

Adam Richter <[email protected]> Thu, 13 Aug 2020 04:28:51 -0700
Newsgroups gmane.comp.video.graphicsmagick.help
Message-ID <CAGn-Tgg7ZNO0WK1zKJx4+vZF9xj=prMQJaDpnJ=w-V=qz8zzew@mail.gmail.com>
When I attempt to see the geometry that would result from "gm convert
-trim", I always get a +0+0 offset.  In comparison, with ImageMagick I
get non-zero offsets.  I think that this may be a bug in
GraphicsMagick, but I want to ask on the help mailing list, in case
there is some other more standard way to get the information using the
command line (as opposed to writing something in the API).

Here is an example of GraphicsMagick vs. ImageMagick, using an image
that I previously surrounded with a pixel high and wide solid border:

$ gm convert -trim 001_bordered.pnm info:-
001_bordered.pnm PPM 2628x3332=>2624x3328+0+0 DirectClass 8-bit 0.020u
0m:0.024996s (334.1Mi pixels/s)

$ convert -trim 001_bordered.pnm info:-
001_bordered.pnm PPM 2624x3328 2628x3332+2+2 8-bit sRGB 25.0526MiB
0.260u 0:00.040

Notice how the ImageMagick version correctly shows the "+2+2" offset.

In case anyone is wondering what the application of this is, it is
from a shell script that compares front and back images from a scanner
and trims to the smallest rectangle that contains both the front and
back, which has been helpful in dealing with situations where one side
of a document has a color very close to the scanner's background
surface, but the other side is not (or sometimes just an area along
one edge of one side), especially after doing some blur and fuzz to
avoid the variations in that background.  One important point to
understand about this use case is that I do not simply want the
resultant image from "-trim".  I just want the geometries, and then I
want to crop the image with a new geometry that is basically the
bounding box of the union of two different trim results.

Thanks in advance for any advice about this.

Adam