def python_blobify(self, img, layer, blur): """The function that actually does the work""" img.undo_group_start() img.select_item(Gimp.ChannelOps.REPLACE, layer) Gimp.Selection.invert(img) c = Gimp.RGB() c.set(0, 0, 0) Gimp.get_pdb().run_procedure('script-fu-drop-shadow', [ Gimp.RunMode.NONINTERACTIVE, GObject.Value(Gimp.Image, img), GObject.Value(Gimp.Drawable, layer), GObject.Value(GObject.TYPE_DOUBLE, -3), GObject.Value(GObject.TYPE_DOUBLE, -3), GObject.Value(GObject.TYPE_DOUBLE,blur), c, GObject.Value(GObject.TYPE_DOUBLE, 80.0), GObject.Value(GObject.TYPE_BOOLEAN, False) ]) # Gimp.get_pdb().run_procedure('gimp-selection-none', [img]) Gimp.Selection.none(img) img.undo_group_end()
def create_RGB_from_string(cls, colorName): """ Create a Gimp.RGB from a string. """ result = Gimp.RGB() # TODO Gimp.RGB.parse_name does what when colorName invalid? # the GIR doc does not say what # result.parse_name(colorName, -1) # -1 means null terminated # TODO the GIR doc says len should be passed, possibly -1 # The following doesn't seem to throw for invalid name. result.parse_name(colorName) return result
def create_RGB_from_tuple(cls, tuple): """ Create a Gimp.RGB from a tuple. Expects a 3-tuple. If tuple has less than three items, will raise Exception If tuple has more than three items, will use the first three. TODO alpha? """ result = Gimp.RGB() # upcast to type float when type int was passed # TODO Gimp.RGB.set does what when values are out of range ??? result.set(float(tuple[0]), float(tuple[1]), float(tuple[2])) return result
def foggify(procedure, run_mode, image, drawable, args, data): name = args.index(0) turbulence = args.index(1) opacity = args.index(2) if run_mode == Gimp.RunMode.INTERACTIVE: # TODO: add a GUI. This first port works just with default # values. color = Gimp.RGB() color.set(240.0, 180.0, 70.0) Gimp.context_push() image.undo_group_start() if image.base_type() is Gimp.ImageBaseType.RGB: type = Gimp.ImageType.RGBA_IMAGE else: type = Gimp.ImageType.GRAYA_IMAGE fog = Gimp.Layer.new(image, name, drawable.width(), drawable.height(), type, opacity, Gimp.LayerMode.NORMAL) fog.fill(Gimp.FillType.TRANSPARENT) image.insert_layer(fog, None, 0) Gimp.context_set_background(color) fog.edit_fill(Gimp.FillType.BACKGROUND) # create a layer mask for the new layer mask = fog.create_mask(0) fog.add_mask(mask) # add some clouds to the layer Gimp.get_pdb().run_procedure('plug-in-plasma', [ GObject.Value(Gimp.RunMode, Gimp.RunMode.NONINTERACTIVE), GObject.Value(Gimp.Image, image), GObject.Value(Gimp.Drawable, mask), GObject.Value(GObject.TYPE_INT, int(time.time())), GObject.Value(GObject.TYPE_DOUBLE, turbulence), ]) # apply the clouds to the layer fog.remove_mask(Gimp.MaskApplyMode.APPLY) fog.set_visible(True) Gimp.displays_flush() image.undo_group_end() Gimp.context_pop() return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())
def __init__(self, r=None, g=None, b=None, name=None, a_tuple=None, adaptee=None): ''' !!! In call to constructor, you must use a keyword assert ( (r is not None and g is not None and b is not None) # and are numbers or (name is not None) # and is str from a certain subset or (a_tuple is not None) # and is a 3-tuple or sequence of number or (adaptee is not None) # and is-a RGB ) ''' try: if r is not None: # Totally new adaptee, created at behest of author or GimpFu implementation # Gimp constructor NOT named "new" a_adaptee = Gimp.RGB() a_adaptee.set(float(r), float(g), float(b)) elif name is not None: a_adaptee = GimpfuRGB.create_RGB_from_string(name) elif a_tuple is not None: a_adaptee = GimpfuRGB.create_RGB_from_tuple(a_tuple) elif adaptee is not None: # Create wrapper for existing adaptee (from Gimp) # Adaptee was created earlier at behest of Gimp user and is being passed into GimpFu plugin a_adaptee = adaptee else: raise RuntimeError("Illegal call to GimpfuRGB constructor") except Exception as err: proceed(f"Creating GimpfuRGB: {err}") # Adapter super().__init__(a_adaptee)
# apply the clouds to the layer fog.remove_mask(Gimp.MaskApplyMode.APPLY) fog.set_visible(True) Gimp.displays_flush() image.undo_group_end() Gimp.context_pop() config.end_run(Gimp.PDBStatusType.SUCCESS) return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error()) _color = Gimp.RGB() _color.set(240.0, 0, 0) class Foggify(Gimp.PlugIn): ## Parameters ## __gproperties__ = { "name": (str, _("Layer _name"), _("Layer name"), _("Clouds"), GObject.ParamFlags.READWRITE), "turbulence": (float, _("_Turbulence"), _("Turbulence"), 0.0, 10.0, 1.0, GObject.ParamFlags.READWRITE), "opacity": (float, _("O_pacity"), _("Opacity"), 0.0, 100.0, 100.0, GObject.ParamFlags.READWRITE), } # I use a different syntax for this property because I think it is # supposed to allow setting a default, except it doesn't seem to