script-fu - how to refer to the active image? - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP) +--- Thread: script-fu - how to refer to the active image? (/Thread-script-fu-how-to-refer-to-the-active-image) Pages:
1
2
|
script-fu - how to refer to the active image? - stabilo - 06-26-2020 Hi, I'm a newbie. I can't figure out how to refer to the active image in a non-interactive script. The example scripts I find all refer to either a new image, or an image loaded from disk, or looping through the image list, or assuming you're working on the rightmost image, or the image comes as a parameter from the dialog (for interactive scripts). I haven't been successful in locating an example that just uses an already opened active image. So if i have an image open and active, and I want a non-interactive script to reduce opacity of that selected image with a fixed amount and then save the image, how do i refer to the image (and drawable)? tnx! RE: script-fu - how to refer to the active image? - Ofnuts - 06-26-2020 (06-26-2020, 04:36 AM)stabilo Wrote: Hi, I'm a newbie. I can't figure out how to refer to the active image in a non-interactive script. The example scripts I find all refer to either a new image, or an image loaded from disk, or looping through the image list, or assuming you're working on the rightmost image, or the image comes as a parameter from the dialog (for interactive scripts). I haven't been successful in locating an example that just uses an already opened active image. Let's be clear on the vocabulary:
The secret is:
Final note: you don't reduce the opacity of an image but the opacity of a layer in the image, so you will need both arguments. RE: script-fu - how to refer to the active image? - stabilo - 06-26-2020 (06-26-2020, 05:42 AM)Ofnuts Wrote: Thanks for replying so quickly! RE: script-fu - how to refer to the active image? - flauapaua - 12-10-2022 I have a problem related to this, so I hope it is okay if I reply in this thread. I tried to modify this script to get a reference if it is started while an image is active. These parts got modified. 1. an additional line Code: SF_IMAGE "image" "whatever" ;image variable in script-fu-register, so it now looks like this Code: "" ;image type that the script works on 2. Code: (define (script-fu-text-box inText inFont inFontSize inTextColor inBufferAmount) ... got modified to Code: (define (script-fu-text-box inImage inText inFont inFontSize inTextColor inBufferAmount) ... However after saving this and refreshing the scripts the menu entry for the script disappeared. Now I'm stuck. RE: script-fu - how to refer to the active image? - programmer_ceds - 12-10-2022 (12-10-2022, 12:10 PM)flauapaua Wrote: ... The menu entry disappearing means that GIMP has identified a problem with the script. If you can run GIMP from a terminal it should show you what the problem is (you will probably have to search through quite a lot of output but if you copy and paste the contents of the terminal window into a text editor you could search for the name of your script). RE: script-fu - how to refer to the active image? - flauapaua - 12-10-2022 (12-10-2022, 04:50 PM)programmer_ceds Wrote: If you can run GIMP from a terminal it should show you what the problem is (you will probably have to search through quite a lot of output but if you copy and paste the contents of the terminal window into a text editor you could search for the name of your script).It seems actually not so bad. This is what I get Code: :~$ /usr/bin/gimp I tried to attach the whole script to this post, but it tells me, that this type of file is not allowed. RE: script-fu - how to refer to the active image? - Ofnuts - 12-11-2022 (12-10-2022, 09:49 PM)flauapaua Wrote: I tried to attach the whole script to this post, but it tells me, that this type of file is not allowed. You can copy-paste the text in a [code] bracket, that you can create clicking the "code" icon above the composer window ( the <> over scroll, 5th icon from right). You can also put it in a ZIP an attach the ZIP. Also, if you put a SF_IMAGE, the image type should be "*", and of course the script won't be enabled until you have an image open (but of course it will always appear in the menus). RE: script-fu - how to refer to the active image? - flauapaua - 12-12-2022 (12-11-2022, 07:29 AM)Ofnuts Wrote: Also, if you put a SF_IMAGE, the image type should be "*", and of course the script won't be enabled until you have an image open (but of course it will always appear in the menus).So this goes into the second column in Code: script-fu-register Code: (script-fu-register Tough luck however. Gimp still complains about the unbound variable znd shows no menu entry. Even if I create an image by the way. Code: (script-fu:12523): GLib-WARNING **: 18:17:28.269: (../../../glib/gerror.c:761):g_error_new_valist: runtime check failed: (domain != 0) RE: script-fu - how to refer to the active image? - programmer_ceds - 12-13-2022 The "*" should be in the line before the SF-IMAGE line. Specifying "" means that the script will be enabled whether or not there is an active image - which makes the SF-IMAGE parameter redundant - probably not what you want. A minor correction to what Ofnuts said - the script will only appear in the menu if GIMP hasn't detected a problem with it. In your case GIMP has detected a problem so no script in the menu. It might be worth you looking at the standard Script-Fu scripts for V2.10 - the latest versions are at: https://gitlab.gnome.org/GNOME/gimp/-/tree/gimp-2-10/plug-ins/script-fu/scripts If GIMP is open and you make a change to a Python script it will take effect the next time you run the script (you don't have to stop and restart GIMP). However, with a Script-Fu script any changes that you make to the script will not take effect until you either stop and restart GIMP or use "Filters/Script-Fu/Refresh Scripts" (note that this second option doesn't currently work with GIMP V2.99 - it simply removes all Script-Fu scripts from the menus!) RE: script-fu - how to refer to the active image? - flauapaua - 12-14-2022 (12-13-2022, 01:57 PM)programmer_ceds Wrote: The "*" should be in the line before the SF-IMAGE line. So, like this, right? Code: "*" ;image type that the script works on (12-13-2022, 01:57 PM)programmer_ceds Wrote: Specifying "" means that the script will be enabled whether or not there is an active image - which makes the SF-IMAGE parameter redundant - probably not what you want.Actually I don't care at this point. I want a reference to the image, if there is an image. If I get a NULL or whatever undefined value, in case nothing is open, is unimportant to me right now. (12-13-2022, 01:57 PM)programmer_ceds Wrote: A minor correction to what Ofnuts said - the script will only appear in the menu if GIMP hasn't detected a problem with it. In your case GIMP has detected a problem so no script in the menu.Ok. I mean, not ok: I want to get rid of this problem. But I understand, what you are saying. (12-13-2022, 01:57 PM)programmer_ceds Wrote: It might be worth you looking at the standard Script-Fu scripts for V2.10 - the latest versions are at:I don't understand them. E.g there is https://gitlab.gnome.org/GNOME/gimp/-/blob/gimp-2-10/plug-ins/script-fu/scripts/old-photo.scm which might be similar to what I want, judging from the inImage in Code: (define (script-fu-old-photo inImage inLayer inDefocus inBorderSize inSepia inMottle inCopy) Code: inImage (12-13-2022, 01:57 PM)programmer_ceds Wrote: However, with a Script-Fu script any changes that you make to the script will not take effect until you either stop and restart GIMP or use "Filters/Script-Fu/Refresh Scripts" (note that this second option doesn't currently work with GIMP V2.99 - it simply removes all Script-Fu scripts from the menus!) I'll do the restart thing to be on the secure side. If I regress the script to Code: "*" ;image type that the script works on it gets through quite nicely. But I want to write a script, that operates on an existing image. |