Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GEGL Drop Shadow: A New Attempt
#2
I've done a bit of experimenting since posting this, but I still don't have a surefire answer. I edited MareroQ's script to send a message with the variable values:

Code:
def gegl_dropshadow(image, layer, shadow_offset_x, shadow_offset_y, shadow_blur, grow_shape, grow_radius, color_s, shadow_opacity):
   
   color_to_gegl=rgb_to_hex(color_s)
   
   if grow_shape==0:
       grow_s='square'
   if grow_shape==1:
       grow_s='circle'
   if grow_shape==2:
       grow_s='diamond'
   
   # Echo all variables
   shadow_offset_x_string = "shadow_offset_x = "   + str(shadow_offset_x)
   shadow_offset_y_string = "\nshadow_offset_y = " + str(shadow_offset_y)
   shadow_blur_string     = "\nshadow_blur = "     + str(shadow_blur)
   grow_shape_string      = "\ngrow_shape = "      + str(grow_shape)
   grow_s_string          = "\ngrow_s = "          + str(grow_s)
   grow_radius_string     = "\ngrow_radius = "     + str(grow_radius)
   color_s_string         = "\ncolor_s = "         + str(color_s)
   color_to_gegl_string   = "\ncolor_to_gegl = "   + str(color_to_gegl)
   shadow_opacity_string  = "\nshadow_opacity = "  + str(shadow_opacity)
   pdb.gimp_message(shadow_offset_x_string + shadow_offset_y_string + shadow_blur_string + grow_shape_string + grow_s_string + grow_radius_string + color_s_string + color_to_gegl_string + shadow_opacity_string)
        
   gegl_graph_string="gegl:dropshadow x=%d y=%d radius=%d grow-shape=%s grow-radius=%d color=%s opacity=%f" % (shadow_offset_x, shadow_offset_y, shadow_blur,grow_s,grow_radius, color_to_gegl, shadow_opacity)
   pdb.python_fu_gegl_graph(image, layer, gegl_graph_string)
register(
   "python_fu_gegl_dropshadow",
   "GEGL to Python. Works on the active layer",
   "Creates a dropshadow effect on the input buffer",
   "Auto Author",
   "Auto Author",
   "Auto Generated Dated",
   "<Image>/GEGL as Python/gegl-dropshadow...",             #Menu path
   "*",
   [

   (PF_SPINNER, "shadow_offset_x", "Shadow Offset X:", 5, (-1000, 1000, 1)),
   (PF_SPINNER, "shadow_offset_y", "Shadow Offset Y:", 5, (-1000, 1000, 1)),
   (PF_SPINNER, "shadow_blur",     "Shadow Blur Radius:", 5, (0, 300, 1)),
   (PF_OPTION,  "grow_shape",      "Grow Shape: ", 0, [" Square "," Circle ", " Diamond "]),    
   (PF_SPINNER, "grow_radius",     "Grow Radius:", 5, (-100, 100, 1)),
   (PF_COLOR,   "color_s",         "Color:", (0, 0, 0)),
   (PF_FLOAT,   "shadow_opacity",  "Shadow Opacity (default:1.5, 0..2):", 1.5)      # (0, 2, 0.01)),  
   ],
   [],
   gegl_dropshadow)

With the preferred settings that I normally use, this is what I got for the output:
Quote:shadow_offset_x = 0.0
shadow_offset_y = 0.0
shadow_blur = 2.0
grow_shape = 1
grow_s = circle
grow_radius = 1.0
color_s = RGB (0.454509803922, 0.787843137255, 0.961176470588, 1.0)
color_to_gegl = #74c9f5
shadow_opacity = 1.25

One big thing that I noticed was that the value I was entering for grow_shape was a string, but it was expecting an integer for the list index from the input. It also seems that I'm entering the colors incorrectly. Here's my updated script with those changes:

Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from gimpfu import*

def generate_hud_outline(image, layer):
   pdb.gimp_image_undo_group_start(image)
   pdb.gimp_selection_none(image)
   pdb.python_fu_gegl_dropshadow(image, layer, 0.0, 0.0, 2.0, 1, 1.0, RGB (0.454509803922, 0.787843137255, 0.961176470588, 1.0), 1.25)
   pdb.gimp_displays_flush()
   pdb.gimp_image_undo_group_end(image)

register(
   "python_fu_marvelmods_common_generate_hud_outline",
   "Generates an outline for a conversation portrait.",
   "Generates an outline for a conversation portrait.",
   "BaconWizard17",
   "BaconWizard17",
   "January 2024",
   "Generate Conversation Portrait (HUD) Outline",
   "*",
   [
       (PF_IMAGE, "image", "Input image", None),
       (PF_DRAWABLE, 'drawable', 'Layer, mask or channel', None)
   ],
   [],
   generate_hud_outline,
   menu='<Image>/Marvel Mods/Utilities'
)

main()

Unfortunately, the errors that I'm getting are the same. 

EDIT: After looking at some more documentation for PF_COLOR, I decided to try updating once more. This time I did just a triple for it instead of putting the RGB and the alpha, like so:

Code:
pdb.python_fu_gegl_dropshadow(image, layer, 0.0, 0.0, 2.0, 1, 1.0, (0.454509803922, 0.787843137255, 0.961176470588), 1.25)

And it worked! The drop shadow is now added as intended.
Modder/Skinner at MarvelMods.com using GIMP to create, edit, and export textures and previews more efficiently.

My GIMP scripts hosted on GitHub
Reply


Messages In This Thread
RE: GEGL Drop Shadow: A New Attempt - by BaconWizard17 - 01-10-2024, 07:33 PM

Forum Jump: