Information about the current selection can be found, even before/after using the selection tools. In Gimp 2.10, this data is exposed using the pdb.gimp_selection_bounds()
function, which can be run from the Python Console (Filters/Python-Fu/Console):
>>> [pdb.gimp_selection_bounds(img) for img in gimp.image_list()]
[(1, 124, 180, 310, 257)]
The 1
here indicates that the selection is not empty, the 124
and 180
show the x and y starting points for the selection, and the 310
and 257
show the x and y ending points for the selection. Note that no matter how complex your selection is, you will still only get back information for a single rectangle encompassing all components of the selection. If you feather a selection, the dimensions will expand to cover even the slightest % selected pixels. There will be more than one entry in the list if you have more than one image open.
>>> pdb.gimp_selection_bounds(gimp.image_list()[0])
(1, 98, 130, 254, 216)
If you know what index the image you care about is in the gimp image list, you can pick it out directly so you don't have to sift through the others.
>>> bounds = [pdb.gimp_selection_bounds(img) for img in gimp.image_list()]
>>> [(bool(b[0]), b[3] - b[1], b[4] - b[2]) for b in bounds]
[(False, 1920, 1080)]
With a little extra work, we can calculate the size of the selection based on the bounds we get back. Here we see that there is no selection; the dimensions of the image are shown instead.
>>> bounds = [pdb.gimp_selection_bounds(img) for img in gimp.image_list()]
>>> [(bool(b[0]), b[3] - b[1], b[4] - b[2]) for b in bounds]
[(True, 186, 77)]
Here we see that there is a selection, and the width and height of the current selection are calculated.
All of this can also be run from the Script-Fu console, but the code will look a little different. For more frequent use, I would recommend creating a plugin to pop up an info box and assigning a keyboard shortcut, but that's a solution I'll leave to the reader.