Sign up now! · Forgot password?
RSS/Atom feed Twitter

How to get the positions(x,y) (width, depth) of selected rectangle or selected ellipse

This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

2020-02-14 06:14:29 UTC (3 days ago)
postings
3
contact
Send private message

How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse

How to get the positions(x,y) (width, depth) of selected rectangle or selected ellipse
I read such numbers on GIMP and write them in Excel files but sometime human error occurs.
I want to automate the process.
I read instructions of Python-Fu but there so many functions then I could not find out how to do it.
Please help me.

tamasakai (via www.gimpusers.com/forums)
ShiroYuki Mot via gimp-user-list
2020-02-14 07:19:20 UTC (3 days ago)

How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse

On Python console, this is what you want. non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image) See, 'gimp-selection-bounds' at Procedure Browser. But, handning values to external App is not so easy. If you add external library 'pyperclip' you can write to clipboard. But it is one value only... Yes, maybe, not suit for you. One solution is that create text layer about that. Then you can copy manually.

2020年2月14日(金) 15:14 tamasakai :

How to get the positions(x,y) (width, depth) of selected rectangle or selected
ellipse
I read such numbers on GIMP and write them in Excel files but sometime human
error occurs.
I want to automate the process.
I read instructions of Python-Fu but there so many functions then I could not
find out how to do it.
Please help me.

--
tamasakai (via www.gimpusers.com/forums) _______________________________________________ gimp-user-list mailing list
List address: gimp-user-list@gnome.org List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list List archives: https://mail.gnome.org/archives/gimp-user-list

Ofnuts
2020-02-14 07:30:24 UTC (3 days ago)

How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse

See:

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

On 2/14/20 7:14 AM, tamasakai wrote:

How to get the positions(x,y) (width, depth) of selected rectangle or selected ellipse
I read such numbers on GIMP and write them in Excel files but sometime human error occurs.
I want to automate the process.
I read instructions of Python-Fu but there so many functions then I could not find out how to do it.
Please help me.

Ofnuts
2020-02-14 07:34:27 UTC (3 days ago)

How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse

Uh? You can write to a file from the script, using the regular I/O functions.

For more structured data you can also use the built-in CSV module to write CSV files, and it is also possible to add excel support to the python runtime.

On 2/14/20 8:19 AM, ShiroYuki Mot via gimp-user-list wrote:

On Python console, this is what you want. non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image) See, 'gimp-selection-bounds' at Procedure Browser. But, handning values to external App is not so easy. If you add external library 'pyperclip' you can write to clipboard. But it is one value only... Yes, maybe, not suit for you. One solution is that create text layer about that. Then you can copy manually.

ShiroYuki Mot via gimp-user-list
2020-02-14 08:12:40 UTC (3 days ago)

How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse

Dear Ofnuts. Thanks! ;) There was a good way!

Is it OK?

with open(file_name, 'w') as f:
writer = csv.writer(f)
writer.writerow([x1, y1, x2, y2])

2020年2月14日(金) 16:34 Ofnuts :

Uh? You can write to a file from the script, using the regular I/O functions.

For more structured data you can also use the built-in CSV module to write CSV files, and it is also possible to add excel support to the python runtime.

On 2/14/20 8:19 AM, ShiroYuki Mot via gimp-user-list wrote:

On Python console, this is what you want. non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image) See, 'gimp-selection-bounds' at Procedure Browser. But, handning values to external App is not so easy. If you add external library 'pyperclip' you can write to clipboard. But it is one value only... Yes, maybe, not suit for you. One solution is that create text layer about that. Then you can copy manually.

_______________________________________________ gimp-user-list mailing list
List address: gimp-user-list@gnome.org List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list List archives: https://mail.gnome.org/archives/gimp-user-list

2020-02-17 00:52:40 UTC (about 10 hours ago)
postings
3
contact
Send private message

How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse

Dear Ofnuts. Thanks! ;) There was a good way!

Is it OK? 2020年2月14日(金) 16:34 Ofnuts :

Thank you for all members replied to my questions. I am jast a biginner of GIMP.
So please tell me step by step with patience.

Then, I wrote a script, made a image named "sample.xcf" and made a rectangle selection on it.
The script on Python Consol made errors. What should I do next?
--------------------------------
# How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse
(non_empty,x1,y1,x2,y2) = selection_bounds (sample.xcf) with open(file_name, 'w') as f:
writer = csv.writer(f)
writer.writerow([x1, y1, x2, y2])
main()
------------------------------

tamasakai (via www.gimpusers.com/forums)
ShiroYuki Mot via gimp-user-list
2020-02-17 01:31:22 UTC (about 9 hours ago)

How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse

Please learn the basic scripting of GIMP Python. See as follows.
https://www.gimp.org/docs/python/index.html

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 ...' image
import csv
file_name = "c:\\Users\\YourName\\Documents\\Temp\\SampleXcfCsv.txt" file_name
non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image) x1
y1
x2
y2
with open(file_name, 'w') as f:
writer = csv.writer(f)
writer.writerow([x1, y1, x2, y2])

2020年2月17日(月) 9:52 tamasakai :

Dear Ofnuts. Thanks! ;) There was a good way!

Is it OK? 2020年2月14日(金) 16:34 Ofnuts :

Thank you for all members replied to my questions. I am jast a biginner of GIMP.
So please tell me step by step with patience.

Then, I wrote a script, made a image named "sample.xcf" and made a rectangle
selection on it.
The script on Python Consol made errors. What should I do next?
--------------------------------
# How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse
(non_empty,x1,y1,x2,y2) = selection_bounds (sample.xcf) with open(file_name, 'w') as f:
writer = csv.writer(f)
writer.writerow([x1, y1, x2, y2])
main()
------------------------------

-- tamasakai (via www.gimpusers.com/forums) _______________________________________________ gimp-user-list mailing list
List address: gimp-user-list@gnome.org List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list List archives: https://mail.gnome.org/archives/gimp-user-list

ShiroYuki Mot via gimp-user-list
2020-02-17 02:22:54 UTC (about 8 hours ago)

How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse

If you can read the Japanese, please see the next. It is my blog post. :)
https://shiroyuki-mot-says.blogspot.com/2020/02/gimp-script-py-create-csv-file.html

2020年2月17日(月) 10:31 ShiroYuki Mot :

Please learn the basic scripting of GIMP Python. See as follows.
https://www.gimp.org/docs/python/index.html

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 ...' image
import csv
file_name = "c:\\Users\\YourName\\Documents\\Temp\\SampleXcfCsv.txt" file_name
non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image) x1
y1
x2
y2
with open(file_name, 'w') as f:
writer = csv.writer(f)
writer.writerow([x1, y1, x2, y2])

2020年2月17日(月) 9:52 tamasakai :

Dear Ofnuts. Thanks! ;) There was a good way!

Is it OK? 2020年2月14日(金) 16:34 Ofnuts :

Thank you for all members replied to my questions. I am jast a biginner of GIMP.
So please tell me step by step with patience.

Then, I wrote a script, made a image named "sample.xcf" and made a rectangle
selection on it.
The script on Python Consol made errors. What should I do next?
--------------------------------
# How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse
(non_empty,x1,y1,x2,y2) = selection_bounds (sample.xcf) with open(file_name, 'w') as f:
writer = csv.writer(f)
writer.writerow([x1, y1, x2, y2])
main()
------------------------------

-- tamasakai (via www.gimpusers.com/forums) _______________________________________________ gimp-user-list mailing list
List address: gimp-user-list@gnome.org List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list List archives: https://mail.gnome.org/archives/gimp-user-list

2020-02-17 06:07:02 UTC (about 4 hours ago)
postings
3
contact
Send private message

How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse

Shiro Yuki -san,
Thanks a lot.
As you mentioned, I am a Japanese.
I asked the same question on Yahoo! Chie-bukuro but there was no good answer. Then I signed up here.
I will learn Python more to achieve my job according to your advice. Thank you very much.

If you can read the Japanese, please see the next. It is my blog post. :)
https://shiroyuki-mot-says.blogspot.com/2020/02/gimp-script-py-create-csv-file.html

2020年2月17日(月) 10:31 ShiroYuki Mot :

tamasakai (via www.gimpusers.com/forums)