Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gimp selected area coordinates with python

I want to get selected area px coordinates of an image. I use gimp and can i see that on the python fu console as real time debugging ?

I'm planning to free select some area on picture and i want to learn it on console. Which coordinates are in that selected area ?

like image 796
Murat Avatar asked Sep 26 '26 17:09

Murat


1 Answers

First of all, when in Python concole, you have to geta reference to the working image - the easier way to get that is to call gimp.image_list() - this present you with a list of the open images in the reversed order they appear on the tabs in the "single window" mode. So, to get the last oppened image, you can type:

 image = gimp.image_list()[0]

(and press <enter>) If you type "image" and presse , you will inspect its contents - Python will display the standard representation of an Image object: <gimp.Image '[Untitled]'> - now, this image object, and its layers (which Pyton exposes in the as a list on the image.layers attribute) can be passed as parameters to hundreds of functions you can easily search if you press the browse button on the bottom of the dialog. After finding the wanted method, just click on apply on the PDB browsing dialog, and the function and its needed parameters will be pasted on the Python prompt -if needed, edit the parameters to fit your needs, and call it by pressing ; In this case you want to call ("gimp_get_selection_bounds"):

>>> non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image)

And your wanted values are now in the variables x1, y1, x2 and y2. If you want just to display them, delete the command up to the pdb and the returned values will be just printed.

If you will work on this often, it will be seriously usefull to learn a little of Python - the tutorial on the http://python.org site will be able to help you a lot.

like image 181
jsbueno Avatar answered Sep 28 '26 08:09

jsbueno



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!