Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # This is a GIMP script written in Python for putting an outline around text (or indeed anything
- # else).
- #
- # To use this script, make sure that the selected layer is the one that you want to outline, then
- # choose "Text Outliner" from the "Layer" menu.
- #
- # You will then be able to set various parameters for the outline. They are:
- # Thickness - thickness of the outline (in pixels)
- # Feather - how soft you want the edge of the outline to be
- #
- # The script will create a new, transparent layer underneath your selected layer filled with
- # the background color. Then the text layer will merge down onto the outline layer and will
- # add a new animstack tag with the original layer name.
- from gimpfu import *
- # Adds a new layer beneath the given layer. Return value is the new layer
- def add_new_layer_beneath(image, layer):
- # Get the layer position.
- pos = 0;
- for l in image.layers:
- if (l == layer):
- break
- else:
- pos += 1
- if image.base_type is RGB:
- type = RGBA_IMAGE
- else:
- type = GRAYA_IMAGE
- # Add a new layer below the selected one
- title = layer.name + ' [fg>' + layer.name + ']'
- new_layer = gimp.Layer(image, title, image.width, image.height, type, 100, NORMAL_MODE)
- image.add_layer(new_layer, pos+1)
- return new_layer
- # Selects the contents of the given layer, then grows it by "thickness"
- # and feathers it by "feather" pixels
- def create_selection(image, layer, thickness, feather):
- # Select the text
- pdb.gimp_selection_layer_alpha(layer)
- # Grow the selection
- pdb.gimp_selection_grow(image, thickness)
- # Feather it
- if (feather > 0):
- pdb.gimp_selection_feather(image, feather)
- return
- # Fills the current selection using the given colour, painting onto the
- # given layer.
- def fill_selection(layer):
- # Fill the selection using the background color
- pdb.gimp_bucket_fill(layer, 1, 0, 100, 0, 0, 1, 1)
- return
- def merge_down(image, layer):
- # Merge the existing layer down. Second argument is GimpMergeType:
- # https://developer.gimp.org/api/2.0/libgimp/libgimp-gimpenums.html#GimpMergeType
- image.merge_down(layer, 1); # Clip to image
- return
- # our script
- def add_text_outline(image, layer, thickness, feather) :
- gimp.progress_init("Drawing outline around text")
- new_layer = add_new_layer_beneath(image, layer)
- gimp.progress_update(33)
- create_selection(image, layer, thickness, feather)
- gimp.progress_update(66)
- fill_selection(new_layer)
- merge_down(image, layer)
- gimp.progress_update(100)
- return
- # This is the plugin registration function
- register(
- "text_outliner",
- "Text Outliner",
- "Will draw an outline around text using the background color.",
- "Pete Nu",
- "Pete Nu",
- "Feb 2015",
- "<Image>/Layer/Text Outline",
- "*",
- [
- (PF_INT, 'outline_thickness', 'Thickness', 6),
- (PF_INT, 'outline_featheriness', 'Feather', 7)
- ],
- [],
- add_text_outline)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement