Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I use the non-legacy version of Emboss from Python-fu?
#1
(07-10-2024, 01:12 AM)weanoob Wrote: I'm writing a script that involves the use of emboss to create a specific effect. When I try
Code:
pdb.plug_in_emboss
 it uses the legacy emboss effect. How can I use the non-legacy version from python?



(I was told to post this in Extending the GIMP, then saw this subforum and decided to start it here instead.)
Reply
#2
There is no easy way to call the GEGL tools from a script, but it can be done, see here.
Reply
#3
Go and have a look through Kevins post as Ofnuts link, there are other posts on the GimpChat forum.

To get you started. The GEGL syntax for emboss is here:  https://gegl.org/operations/gegl-emboss.html

You can check for a valid command using Generic -> GEGL graph

   

...but to include that into a python script you need a utility plugin such as the attached gegl_command.py . Your script will call that plugin. Also in the attached zip is an example for_gegl.py

Unzip, and put both in your plugins folder.  The example registers in the tools menu as run_gegl I have tried in Win10 / Gimp 2.10.38 - it does work.


Attached Files
.zip   for_gegl.zip (Size: 1.34 KB / Downloads: 65)
Reply
#4
I figured it out. I will not let this be a "PM'd you the fix Big Grin " moment.


Code:
from gimpfu import *
import pygtk
import gtk
from sys import argv, platform
from ctypes import *

def load_library (library_name):
    if platform == "linux" or platform == "linux2":
        library_name = library_name + '.so.0'
    elif platform == "win32":
        from ctypes.util import find_library
        library_name = find_library (library_name + "-0")
    else:
        raise BaseException ("TODO")
    return CDLL (library_name)
    

gimp = load_library('libgimp-2.0')

def use_gegl_graph(image, drawable, gegl_graph_string):
    class GeglBuffer(Structure):
        pass
    drawable_id = drawable.ID
    
    gegl = load_library ('libgegl-0.4')
    sucess = gegl.gegl_init (None, None)
    gimp.gimp_drawable_get_shadow_buffer.restype = POINTER (GeglBuffer)
    gimp.gimp_drawable_get_buffer.restype        = POINTER (GeglBuffer)

    x = c_int (); y = c_int (); w = c_int (); h = c_int ()
    non_empty,x,y,w,h = pdb.gimp_drawable_mask_intersect (drawable)
    args = [b"string", c_char_p (gegl_graph_string), c_void_p ()]
    
    if non_empty:
        source = gimp.gimp_drawable_get_buffer (drawable_id)
        target = gimp.gimp_drawable_get_shadow_buffer (drawable_id)
        sucess = gegl.gegl_render_op (source, target, "gegl:gegl", *args)
        gegl.gegl_buffer_flush (target)
        gimp.gimp_drawable_merge_shadow (drawable_id, PushUndo = True)
        gimp.gimp_drawable_update (drawable_id, x, y, w, h)
        gimp.gimp_displays_flush ()

def emboss(timg, tdrawable, depth=4, elevation=12.5):
   gegl_graph_string = "emboss azimuth=30.0 depth={0} elevation={1}".format(depth, elevation)
   use_gegl_graph(timg, tdrawable, gegl_graph_string)

I don't remember where I got most of this code from, probably this forum.
Reply


Forum Jump: