I'll make a rectangle selection in image. I have to read the left, right, up and down dimensions of this selected region in full image. The following image is an example of this.

enter image description here


Can we print the following variables in the window or debug screen?

Units in mm.

L = X of Selection Bounding Box
U = Y of Selection Bounding Box
D = H of Image - (H of Selection Bounding Box + U)
R = W of Image - (W of Selection Bounding Box + L)

This example image is 200px x 200px. If you don't know it, you can find the size by clicking Image > Canvas Size

enter image description here

The Crop Tool options show the X and Y position of the top left corner of the crop, and the X and Y size of the crop. So it's simple arithmetic to work out the distances.

Left = 33px

Up = 49px

Right = 200-33-129 = 38px

Down = 200-49-96 = 55px

  • You're right. But can Gimp do this automatically? Can a script be embedded in Gimp? Because I have a lot of pictures to do. Or is there a program that can do this?
    – Özgür
    May 28 '19 at 0:35
  • GIMP can run Script-fu and Python-fu scripts - but don't ask me how to write one. I've no idea.
    – Billy Kerr
    May 28 '19 at 0:37

A very basic python script that does it:

#!/usr/bin/env python
from gimpfu import *

def selectionMargins(image):
    if not selection:
        pdb.gimp_message("No selection")
        gimp.message('L=%d\nU=%d\nR=%d\nD=%d' % (x1,y1,image.width-x2,image.height-y2))

### Registration
desc='Show selection margins'
    [(PF_IMAGE, "image", "Input image", None),],[],

  • Copy the script to a text file with .py extension (note: python is sensitive to the indentation of the code)
  • See Edit>Preferences>Folder>Plugins for the folder whre the resulting file should be
  • On OSX and Linux, make it executable
  • The menu entry is at the bottom of the Select menu in an image window.
  • Output is in a dialog or in the error console window if it up

enter image description here

It wouldn't be difficult to improve the script to append to a CSV file a line with the image file name/path and the values.

  • Of course, very basic for you. I don't know this matter. I'm away from my computer right now. I'll try as soon as I get to the computer.
    – Özgür
    May 30 '19 at 11:54
  • 5 lines of code, once you have removed the boilerplate :)
    – xenoid
    May 30 '19 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.