Re: [Gimp-user] How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse

If you register your script properly, the Image will be in the function
arguments when the script is called from the menu,
no need to read it out from the title bar.

Also, you can avoid a lot of back-slashing by either:

- Using "raw" notation for string literals:

    file_name = r'c:\Users\YourName\Documents\Temp\SampleXcfCsv.txt'

- Using triple quoting:


- Using forward slashes, that work just as well (the Windows API
understands both types, it's just the command-prompt parser
that insists on backslashes):


On 2/17/20 2:31 AM, ShiroYuki Mot via gimp-user-list wrote:
Please learn the basic scripting of GIMP Python.
See as follows.

If opened image by GIMP is one only at first and it has one layer and a
selection is existing.
Example on Windows OS - Python Console.

image = gimp._id2image(1)
# 1 is shown at GIMP Title-Bar as '[Name] (Status)- 1.0 (RGB ...'
import csv
file_name = "c:\\Users\\YourName\\Documents\\Temp\\SampleXcfCsv.txt"
non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image)
with open(file_name, 'w') as f:
   writer = csv.writer(f)
   writer.writerow([x1, y1, x2, y2])

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]