It is currently Thu Apr 25, 2024 3:28 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 18 posts ] 
Author Message
 Post subject: How to access image properties in script-fu?
PostPosted: Tue Sep 27, 2016 4:38 am  (#1) 
Offline
New Member

Joined: Sep 27, 2016
Posts: 2
Hi,
I am new to GIMP. I know Lisp, so I want to learn to write Script-fu scripts.

The first thing I want to do is to be able to get the image properties in the script. Specifically, I want to get the "Comments" part of the image properties. How to do this? I searched in the procedure browser, but could not find a direct way.

Thanks for your help.

Regards,
Rangarajan


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: How to access image properties in script-fu?
PostPosted: Tue Sep 27, 2016 8:34 am  (#2) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4739
It's in a "parasite". In Python:
image_comments=image.parasite_find('gimp-comment').data

Something similar(*) is likely available in script-fu.

(*) but, of course, more convoluted

_________________
Image


Top
 Post subject: Re: How to access image properties in script-fu?
PostPosted: Tue Sep 27, 2016 5:10 pm  (#3) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
it's definitely not straight forward in scheme,
(gimp-image-get-parasite "gimp-comment")

which returns a list of a list that looks like
(("gimp-comment" 1 "This is a test comment"))

so to get at the comment you have to do something like
(set! comment (list-ref (car (gimp-image-get-parasite image "gimp-comment")) 2))

_________________
TinT


Top
 Post subject: Re: How to access image properties in script-fu?
PostPosted: Tue Sep 27, 2016 9:13 pm  (#4) 
Offline
New Member

Joined: Sep 27, 2016
Posts: 2
Thank you! Both work as expected.

Regards,
Rangarajan


Top
 Post subject: Re: How to access image properties in script-fu?
PostPosted: Wed Sep 28, 2016 6:28 am  (#5) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4739
trandoductin wrote:
it's definitely not straight forward in scheme,


Nothing is :)

_________________
Image


Top
 Post subject: Re: How to access image properties in script-fu?
PostPosted: Wed Sep 28, 2016 12:52 pm  (#6) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
.py is more fun to work with that's for sure.
in python, pdb.gimp_image_get_parasite(image,"gimp-comment")
returns the string we want. I tried both scheme and python to see what's going on.

_________________
TinT


Top
 Post subject: Re: How to access image properties in script-fu?
PostPosted: Wed Sep 28, 2016 1:11 pm  (#7) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
Tin, what's wrong in my sequence at python console?

>>> nr,ids = pdb.gimp_image_list()
>>> myimage = ids[0]
>>> comment = pdb.gimp_image_get_parasite (myimage, "gimp-comment")
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: wrong parameter type
>>>

_________________
"Where am I ?"


Top
 Post subject: Re: How to access image properties in script-fu?
PostPosted: Wed Sep 28, 2016 1:40 pm  (#8) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
when you use pdb.gimp_image_list it returns image ids not image objects

try this
images = gimp.image_list()
myimage = images[0]
comment = pdb.gimp_image_get_parasite (myimage, "gimp-comment")

_________________
TinT


Top
 Post subject: Re: How to access image properties in script-fu?
PostPosted: Wed Sep 28, 2016 1:51 pm  (#9) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
thanks Tin, but...
>>> images = gimp.image_list()
>>> myimage = images[0]
>>> comment = pdb.gimp_image_get_parasite (myimage, "gimp-comment")
Traceback (most recent call last):
File "<input>", line 1, in <module>
RuntimeError: execution error
>>>

_________________
"Where am I ?"


Top
 Post subject: Re: How to access image properties in script-fu?
PostPosted: Wed Sep 28, 2016 2:07 pm  (#10) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
that's exactly what i have i don't know what's different
here check out this example
Attachment:
arc_example.zip [1.42 KiB]
Downloaded 142 times

I named it funny because i just used another script's code as wrapper.

_________________
TinT


Top
 Post subject: Re: How to access image properties in script-fu?
PostPosted: Wed Sep 28, 2016 2:14 pm  (#11) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
so, it's again something happening in my PC now, maybe tomorrow it will work...

_________________
"Where am I ?"


Top
 Post subject: Re: How to access image properties in script-fu?
PostPosted: Wed Sep 28, 2016 2:20 pm  (#12) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
look, Tin

Attachment:
Cattura.PNG
Cattura.PNG [ 24.35 KiB | Viewed 994 times ]

_________________
"Where am I ?"


Top
 Post subject: Re: How to access image properties in script-fu?
PostPosted: Wed Sep 28, 2016 2:22 pm  (#13) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
well, a good sleep until tomorrow, then I'll retry

_________________
"Where am I ?"


Top
 Post subject: Re: How to access image properties in script-fu?
PostPosted: Wed Sep 28, 2016 2:25 pm  (#14) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
that's freakn weird man, it runs fine on mine

_________________
TinT


Top
 Post subject: Re: How to access image properties in script-fu?
PostPosted: Wed Sep 28, 2016 3:35 pm  (#15) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4739
Looks like you have introduced a syntax error after it registered... did you edit it?
Can you run it outside of Gimp (it should say "ImportError: No module named gimpfu")?

_________________
Image


Top
 Post subject: Re: How to access image properties in script-fu?
PostPosted: Wed Sep 28, 2016 4:01 pm  (#16) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
No syntax error - the error is what you get when the image doesn't have a comment.

Kevin


Top
 Post subject: Re: How to access image properties in script-fu?
PostPosted: Wed Sep 28, 2016 5:13 pm  (#17) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
paynekj wrote:
No syntax error - the error is what you get when the image doesn't have a comment.

Kevin

I would have never find this out as I created all my images in GIMP and i think it defaults to have "Created in GIMP" as comment.

_________________
TinT


Top
 Post subject: Re: How to access image properties in script-fu?
PostPosted: Thu Sep 29, 2016 12:08 am  (#18) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
paynekj wrote:
No syntax error - the error is what you get when the image doesn't have a comment.

Kevin

wow, that's it
created an image and...voilà, script worked.
IMO this is a bad behaviour by Gimp, it should be amended to answer with something like "no such a parasite" or "void" or "empty", and not conclude with a runtime error or whatever error msg

_________________
"Where am I ?"


Top
Post new topic Reply to topic  [ 18 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Can you script access the Handle Transform tool?

2

No new posts Attachment(s) Access built-in Kaleidoscope with Python

7

No new posts Permission to access folder SOLVED.

2

No new posts A way to allow GIMP access to removable media - MacOS 10.15

4

No new posts Attachment(s) Script OCR Image (Tesseract OCR engine )

5


cron

* Login  



Powered by phpBB3 © phpBB Group