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.

12 of 12 messages available
Toggle history

Please log in to manage your subscriptions.

How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse tamasakai 14 Feb 06:14
  How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse ShiroYuki Mot via gimp-user-list 14 Feb 07:19
   How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse Ofnuts 14 Feb 07:34
    How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse ShiroYuki Mot via gimp-user-list 14 Feb 08:12
     How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse tamasakai 17 Feb 00:52
      How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse ShiroYuki Mot via gimp-user-list 17 Feb 01:31
       How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse ShiroYuki Mot via gimp-user-list 17 Feb 02:22
        How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse tamasakai 17 Feb 06:07
       How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse Ofnuts 17 Feb 13:11
        How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse ShiroYuki Mot via gimp-user-list 17 Feb 13:45
         How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse tamasakai 18 Feb 04:18
  How to get the positions(x, y) (width, depth) of selected rectangle or selected ellipse Ofnuts 14 Feb 07:30
2020-02-14 06:14:29 UTC (4 months ago)
postings
4
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 (4 months 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 (4 months 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 (4 months 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 (4 months 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 (4 months ago)
postings
4
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 (4 months 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 (4 months 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 (3 months ago)
postings
4
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)
Ofnuts
2020-02-17 13:11:46 UTC (3 months ago)

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:

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

- 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):

file_name="c:/Users/YourName/Documents/Temp/SampleXcfCsv.txt"

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.
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])

ShiroYuki Mot via gimp-user-list
2020-02-17 13:45:03 UTC (3 months ago)

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

Dear Ofnuts. Thanks a lot! :)

I wrote just the basic code, because he seems to be a beginner. But your comments will surely help him.

2020-02-17 22:11 GMT+09:00, Ofnuts :

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:

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

- 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):

file_name="c:/Users/YourName/Documents/Temp/SampleXcfCsv.txt"

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.
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])

_______________________________________________ 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-18 04:18:02 UTC (3 months ago)
postings
4
contact
Send private message

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

Dear Ofnuts. Thanks a lot! :)

I wrote just the basic code, because he seems to be a beginner. But your comments will surely help him.

2020-02-17 22:11 GMT+09:00, Ofnuts :

Thank you all

I tried the script as follows. I could get the selection's position and size! Thanks again.
But the Python script only runs on GIMP 2.10.12 but GIMP.2.10.12 So I use it with downgraded GIMP because the script is very useful for me.

I will try it when new GIMP comes out Thank you

--------------------------------- # coding:utf-8

import csv
import os.path
from gimpfu import *

outpath = "Z:\\outcsv\\data\\out.csv"

def plugin_main(image, layer): current_image = image #gimp.image_list()[0] filename = pdb.gimp_image_get_filename(current_image) non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(current_image) with open(outpath, 'a') as f:
writer = csv.writer(f, lineterminator='\n') writer.writerow([x1,y1,x2-x1,y2-y1,filename])

register( "outcsv",#コマンドラインまたはスクリプトから呼び出す場合のコマンドの名前 "output to csv",#プラグインの説明
"out csv",#プラグインの詳細な説明
"tamasakai",#プラグインの作成者
"tamasakai(copyright)",#プラグインの著作権保有者 (通常は author と同じ) "2020/02/18",#著作権の日付
"/Filters/Languages/Python-Fu/outcsv", #メニューの中でプラグインに使用されるラベル "RGB*, GRAY*", #プラグインで処理する対象となる画像のタイプex. RGB*, GRAY* など [],#引数(型, 名前(プロシージャブラウザに表示される),説明, 初期値) [], # 戻り値
plugin_main) # メソッド名

main() ----------------------------------------------------------------

tamasakai (via www.gimpusers.com/forums)