ImageMagick display WxH+x+y window

In ImageMagick's display, if I press 'c' and start to drag a crop frame, a small box appears at top left showing WxH+x+y for the crop frame.

Is there any way that data can be accessed programmatically in bash, other than taking a screenshot and running tesseract-ocr or the like on the image?


Solution 1:

If you are using X11, the text written in the box is done using graphics commands that are sent over the socket connection to the X11 server. These commands can be inspected by interposing the utility xscope. For example,

xscope -v1 -i1

will start listening for connections to display :1 (-i1) and print to stdout (at verbose level 1) the X11 commands received before sending them on to the real display, presumably :0. So you can then simply run DISPLAY=:1 display my.jpg or similar and look out this output, typically:

         ............REQUEST: PolyText8
                    drawable: DWB 02e002f3
                          gc: GXC 02e00099
                           x: 11
                           y: 18
                       items:
                       delta: 0
          text item 8 string: " 53x48+310+109"

A simple sed script can extract this text item for further processing:

xscope -v1 -i1 |
sed -n '/text item 8 string: " /{s///;s/"//p}'

An alternative program doing a similar job is x11trace, sometimes known as xtrace.

x11trace -D:1

produces output like

000:<:14fa: 32: Request(74): PolyText8 drawable=0x02e002f3 gc=0x02e00099 x=11 y=18 texts={delta=0 s=' 26x38+425+297'};

which can be filtered with

sed -n "/PolyText8 /{s/.*s='//;s/'.*//p}"