Post Reply 

How to 'Script-Fu' an action....

Jan 16, 2012, 12:02
Post: #1
How to 'Script-Fu' an action....
Hello, Greeting from the cold northeast of the UK.

I have a load of images i want to do the same thing to... and figured a script-fu needed to be created in the console.... problem is, i dont understand where to put my variables.

Please can you help?

What am I trying to do? - I'm taking a scanned image of a black logo which is now a gif. the gif that has 'shades of dark' and black on a transparent background > I am then making a whole new gif which is the same logo (but 100% black) and replacing the original.

1) I open an image FILE > Open > double click.... etc.... it opens as a layer called "Background (100ms)" [please note i have no idea where the 100ms bit comes from - but it does]

2) I can right click the layer thumbnail and 'Alpha to Selection' which works (but i have lots to do so i open the console and had a go ...... I guessed the script-Fu in the console for this is action was....

(gimp-selection-layer-alpha layer)

but where do i type the name of the layer? I always get the message

Error: eval: unbound variable: layer

*at this point i fail to progress any further

anyway..... this is what i hope to do and would love some help please...

1)open a .gif image
2)Alpha to selection' on the layer that just opened. (gimp-selection-layer-alpha layer)
3)Create new layer (gimp-image-add-layer image layer position) ????
4)Fill new layer selection with FG colour (in this case black)
5)turn off original background layer
6)save image as *.gif.


Many thanks
Find all posts by this user
Quote this message in a reply
Jan 16, 2012, 13:01
Post: #2
RE: How to 'Script-Fu' an action....
About your process:
  • when you load an image with one "plane" (GIF/JPG/PNG ) Gimp names the corresponding layer "background". I avoid GIF (because outside of animations, the PNG format is always much better suited) but I suspect the "100ms" is the default frame duration if the layer is later used as a frame in an animated GIF.
  • Your process can be replaced by:
    • alpha-lock the layer(*)
    • bucket-fill the layer (paint will only apply to non-transparent pixels due to alpha-lock)
  • when you call your code from a "Filter", two input variables are pre-filled with the image and layer to which the filter is applied. Otherwise you have to set these by requesting the list of images (gimp-image-list), identify your image in the list (easy if it"s the only one), then use a similar technique to find the layer (gimp-image-get-layers). For the first part, If you load the image directly (gimp-file-load), it returns the loaded image

If you want to using Gimp in batch mode (called once for each file) isn't very efficient, it is faster to start Gimp once and have it run on a bunch of files in a directory.

Since you are obviously very new to programming, may I suggest that you use the python-fu scripting instead of the script-fu? Python is a language a lot easier to grasp and you'll find plenty of help at beginner's level. Scheme is a bit more hardcore. The only problem with python is that python support isn't included by default in Windows installers, but it's not that hard to add.

Last, there is also a good chance that this very simple operation can be done using ImageMagick. The list of options is daunting, but mastering IM for your purposes might turnout a lot easier/faster than learning Scheme or Python. They have a forum for support & user help.


(*) gimp-layer-set-lock-alpha or if you want to try manually first:
[attachment=868]

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Jan 16, 2012, 13:24 (This post was last modified: Jan 16, 2012 13:26 by paynekj.)
Post: #3
RE: How to 'Script-Fu' an action....
Welcome from the sunny South West of the UK Wink

Ofnuts gives good advice (as usual), but just to clarify the error you are getting:
(gimp-selection-layer-alpha layer) expects you to pass it the layer-id, which is a number

For instance, if I were to start GIMP and open an image, the image would get an id of 1 and if there is only a single layer in that image, it might have an id of 1
so the call would be (gimp-selection-layer-alpha 1)
BUT the moment you open a new image, or add/delete layers, then the id numbers might be different, so using constants isn't going to work.

Personally I never use the console, but start writing scripts in a text editor.

Kevin
Find all posts by this user
Quote this message in a reply
Jan 16, 2012, 14:12
Post: #4
RE: How to 'Script-Fu' an action....
thank you both.
I used ofnut's 'alphalock' button and did all 78 logos by hand (with a few keyboard shortcuts to make it quicker.....

i'm affraid i couldn't get the numeric thing to work either. i tried in both python and script-fu. but i got a more interesting error message/...

> (gimp-selection-layer-alpha 1)
Error: Procedure execution of gimp-selection-layer-alpha failed on invalid input arguments: Procedure 'gimp-selection-layer-alpha' has been called with an invalid ID for argument 'layer'. Most likely a plug-in is trying to work on a layer that doesn't exist any longer.


is there an 'idiots guide' to scripting fu (or python for that matter) in GIMP.

btw - im running linux mint 12

tahnks
Find all posts by this user
Quote this message in a reply
Jan 16, 2012, 14:46
Post: #5
RE: How to 'Script-Fu' an action....
(Jan 16, 2012 14:12)RickBrock Wrote:  is there an 'idiots guide' to scripting fu (or python for that matter) in GIMP.

btw - im running linux mint 12
If running Linux then Python is definitely a better choice IMHO.

But whether Scheme or Python, writing Gimp scripts requires three almost "orthogonal" skills:

1) Programming (no need for expert level)
2) Some proficiency with Python or Scheme (no need for expert level either)
3) Gimp (the procedure browser makes it quite easy to find by what to replace a manual step)

Reading existing Gimp scripts is always useful. My own sets of Python scripts:

http://sourceforge.net/projects/gimp-tools/
http://sourceforge.net/projects/gimp-path-tools/

Start with the small ones (simpler logic...)

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Jan 16, 2012, 15:14
Post: #6
RE: How to 'Script-Fu' an action....
(Jan 16, 2012 14:12)RickBrock Wrote:  i'm affraid i couldn't get the numeric thing to work either. i tried in both python and script-fu. but i got a more interesting error message/...

> (gimp-selection-layer-alpha 1)
Error: Procedure execution of gimp-selection-layer-alpha failed on invalid input arguments: Procedure 'gimp-selection-layer-alpha' has been called with an invalid ID for argument 'layer'. Most likely a plug-in is trying to work on a layer that doesn't exist any longer.


is there an 'idiots guide' to scripting fu (or python for that matter) in GIMP.

Like I said, the constant "1" is only likely to work in very limited circumstances.

As for guides to scripting (both flavours), The Gimp Chat scripting resource guide is a good place for links: http://gimpchat.com/viewtopic.php?f=9&t=724

And as Ofnuts says, learning by looking at other's scripts is very effective (at least for me it is)
Find all posts by this user
Quote this message in a reply
Jan 16, 2012, 15:40
Post: #7
RE: How to 'Script-Fu' an action....
thanks so much.
God bless.
Rick
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Create new images button & Save as override from Script-fu beniman 12 520 Sep 10, 2014 10:57
Last Post: paynekj
  how to create a shortcut for the action crop? Paul 3 337 Jul 8, 2014 09:26
Last Post: rich2005
  Line Script 2Old 8 628 Feb 6, 2014 21:51
Last Post: ofnuts
  How to record action for automatic repeat umen 2 946 Aug 23, 2013 20:00
Last Post: umen
  Script Fu Slandingo 1 701 Jun 14, 2013 20:26
Last Post: rich2005

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS