Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to work with effects in GIMP Python?
#2
I couldn't find any usefull documentation on DrawableFilterConfig methods. I googled some more found this thread on gimpchat.com GIMP 3 now has GEGL automation in python console. So to set parameters for filters you do this:
Code:
# Get image and selected layer.
image = Gimp.get_images()[0]
layer = image.get_selected_layers()[0]
# Add Threshold Alpha layer fx (Layer > Transparency > Threshold Alpha...).
filter_threshold_alpha = Gimp.DrawableFilter.new(layer, 'gimp:threshold-alpha', 'My Threshold Alpha')
To print the parameters in the console you can use DrawableFilter.get_config().list_properties():  
Code:
for parameter in filter_threshold_alpha.get_config().list_properties():
    parameter.get_name(), parameter.get_default_value()
# To set the parameter to 0 you do
filter_threshold_alpha.get_config().set_property('value', 0.0)
# Append Threshold Alpha filter to the layer.
layer.append_filter(filter_threshold_alpha)
  Now let's add Gaussian Blur  
Code:
# Add Gaussian Blur layer fx (Filters > Blur > Gaussian Blur...).
filter_gaussian_blur = Gimp.DrawableFilter.new(layer, 'gegl:gaussian-blur', 'My Gaussian Blur')
# set properties for Gaussian Blur.
filter_gaussian_blur.get_config().set_property('std-dev-x', 5.5)
filter_gaussian_blur.get_config().set_property('std-dev-y', 5.5)
# If you set the properties after adding the filter to the layer you have to use:
filter_gaussian_blur.update()
  I tried to add all properties for Gaussian Blur at once but  
Code:
filter_gaussian_blur.get_config().set_properties(('std-dev-x', 1.5), ('std-dev-y', 1.5), ('filter', 'auto'), ('abyss-policy', 'clamp'), ('clip-extent', True))
 and  
Code:
filter_gaussian_blur.get_config().set_properties(5.5, 5.5, 'auto', 'clamp', True)
 didn't work either. To merge the filters down use:
Code:
layer.merge_filters()
     

How do you find out what the filter operation’s name are like 'gimp:threshold-alpha' and  'gegl:gaussian-blur' when using Gimp.DrawableFilter.new(drawable, operation_name, name)?
Reply


Messages In This Thread
RE: How to work with effects in GIMP Python? - by joeyeroq - 04-02-2025, 11:34 PM

Forum Jump: