Question

I am having issues re-writing one of the default logo scripts in GIMP(using Script-fu based on scheme). For one thing the alpha layer is not shown in the layer browser after the image is shown. I am re-writing the Create Neon Logo script(neon-logo.scm) and I want it to do the following before it displays the new image:

  1. add an alpha channel
  2. change black(background color) to transparent via colortoalpha
  3. return the generated image as an object to be used in another python script(using for loops to generate 49 images) I have tried modifying the following code to the default script:

        (gimp-image-undo-disable img)
        (apply-neon-logo-effect img tube-layer size bg-color glow-color shadow) *Generates neon logo
        (set! end-layer (car (gimp-image-flatten img))) *Flattens image
        (gimp-layer-add-alpha end-layer) *Adds alpha layer as last layer in img(img=the image)
        (plug-in-colortoalpha img 0 (255 255 255)) *Uses color to alpha-NOT WORKING
        (gimp-image-undo-enable img) *Enables undo
        (gimp-display-new img) *Displays new image
    

For number 3 my python code is this:

        for str1 in list1:
            for color1 in list3:
                img = pdb.script_fu_neon_logo(str1,50,"Swis721 BdOul BT",(0,0,0),color1,0)

But img is a "Nonetype" object. I would like to make it so that instead of displaying the generated image in a new window, it just returns the generated image for use with my python script. Can anyone help?

Was it helpful?

Solution

Maybe to keep everything more managaeable and readable, you should translate theoriginal script into Python - that way you willhaveno surprises on otherwiser trivial things as variable assignment, picking elements from sequences and so on.

1 and 2) your calls are apparantly correct to flaten an "add an alpha channel " (not "alpha layer",a s you write, please) to the image - but you are calling color-to-alpha to make White (255 255 255) transparemt not black. Trey changing that to (0 0 0) - if it does not work, make] each of the calls individually, either on script-fu console or on python console, and check what is wrong.

3) Script-fu can't return values to the caller (as can be seen by not having a "return value type" parameter to the register call. That means that scripts in scheme in GIMP can only render thigns on themselves and not be used to compose more complex chains.

That leaves you with 2 options: port the original script to Python-fu (and them just register it to return a PF-IMAGE) - or hack around the call like this, in Python: create a set with all images opened, call your script-fu, check which of your images currently open is not on the set of images previously opened - that will be your new image:

The tricky part with this is that: there is no unique identifier to an image when you see it from Python-fu - so you 'dhave to compose a value like (name, number_of_layers, size) to go on those comparison sets and even that might not suffice - or youg could juggle with "parasites" (arbitrary data that can be attached to an image). As you can see, having the original script-fu rewriten in Python, since all the work is done by PDB calls, and these translate 1:1, is preferable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top