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

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Alussam
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:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
List archives:   https://mail.gnome.org/archives/gimp-user-list
Reply | Threaded
Open this post in threaded view
|

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

Users mailing list
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 <[hidden email]>:

> 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:    [hidden email]
> List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
> List archives:   https://mail.gnome.org/archives/gimp-user-list
>
_______________________________________________
gimp-user-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
List archives:   https://mail.gnome.org/archives/gimp-user-list
Reply | Threaded
Open this post in threaded view
|

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

Ofnuts-2
In reply to this post by Alussam
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.
>

_______________________________________________
gimp-user-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
List archives:   https://mail.gnome.org/archives/gimp-user-list
Reply | Threaded
Open this post in threaded view
|

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

Ofnuts-2
In reply to this post by Users mailing list
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:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
List archives:   https://mail.gnome.org/archives/gimp-user-list
Reply | Threaded
Open this post in threaded view
|

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

Users mailing list
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 <[hidden email]>:

> 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:    [hidden email]
> List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
> List archives:   https://mail.gnome.org/archives/gimp-user-list
>
_______________________________________________
gimp-user-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
List archives:   https://mail.gnome.org/archives/gimp-user-list
Reply | Threaded
Open this post in threaded view
|

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

Alussam
>Dear Ofnuts. Thanks!  ;) There was a good way!
>
>Is it OK?
>2020年2月14日(金) 16:34 Ofnuts <[hidden email]>:

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:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
List archives:   https://mail.gnome.org/archives/gimp-user-list
Reply | Threaded
Open this post in threaded view
|

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

Users mailing list
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 <[hidden email]>:

> >Dear Ofnuts. Thanks!  ;) There was a good way!
> >
> >Is it OK?
> >2020年2月14日(金) 16:34 Ofnuts <[hidden email]>:
>
> 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:    [hidden email]
> List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
> List archives:   https://mail.gnome.org/archives/gimp-user-list
>
_______________________________________________
gimp-user-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
List archives:   https://mail.gnome.org/archives/gimp-user-list
Reply | Threaded
Open this post in threaded view
|

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

Users mailing list
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 <[hidden email]>:

> 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 <[hidden email]>:
>
>> >Dear Ofnuts. Thanks!  ;) There was a good way!
>> >
>> >Is it OK?
>> >2020年2月14日(金) 16:34 Ofnuts <[hidden email]>:
>>
>> 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:    [hidden email]
>> List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
>> List archives:   https://mail.gnome.org/archives/gimp-user-list
>>
>
_______________________________________________
gimp-user-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
List archives:   https://mail.gnome.org/archives/gimp-user-list
Reply | Threaded
Open this post in threaded view
|

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

Alussam
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 <[hidden email]>:

--
tamasakai (via www.gimpusers.com/forums)
_______________________________________________
gimp-user-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
List archives:   https://mail.gnome.org/archives/gimp-user-list
Reply | Threaded
Open this post in threaded view
|

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

Ofnuts-2
In reply to this post by Users mailing list
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:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
List archives:   https://mail.gnome.org/archives/gimp-user-list
Reply | Threaded
Open this post in threaded view
|

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

Users mailing list
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 <[hidden email]>:

> 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:    [hidden email]
> List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
> List archives:   https://mail.gnome.org/archives/gimp-user-list
>
_______________________________________________
gimp-user-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
List archives:   https://mail.gnome.org/archives/gimp-user-list
Reply | Threaded
Open this post in threaded view
|

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

Alussam
>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 <[hidden email]>:

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",#著作権の日付
    "<Image>/Filters/Languages/Python-Fu/outcsv", #メニューの中でプラグインに使用されるラベル
    "RGB*, GRAY*", #プラグインで処理する対象となる画像のタイプex. RGB*, GRAY* など
    [],#引数(型, 名前(プロシージャブラウザに表示される),説明, 初期値)
    [], # 戻り値
    plugin_main) # メソッド名

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




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