Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from gimpfu import *
- def munge(img, s):
- names = []
- for layer in img.layers:
- names.append(layer.name)
- n = 0
- s1 = s
- while s1 in names:
- s1 = '{}{}'.format(s, n)
- n += 1
- return s1
- def do_stuff(img, layer, initstr, font, size, fgcolor, bgcolor, outline_radius, blur_radius):
- gimp.progress_init("Doing stuff to " + layer.name + "...")
- # Set up an undo group, so the operation will be undone in one step.
- pdb.gimp_undo_push_group_start(img)
- # Save the current foreground color:
- pdb.gimp_context_push()
- # Set the text color
- gimp.set_foreground(fgcolor)
- gimp.set_background(bgcolor)
- # Get position of current selection, if there is one
- # Otherwise, put the new text near top-left of image
- non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(img)
- if non_empty == True:
- x = x1
- y = y1
- else:
- x = 5
- y = 5
- # Create a new text layer (-1 for the layer means create a new layer)
- text_layer = pdb.gimp_text_fontname(
- img, None, x, y, initstr, -1, True, size, PIXELS, font)
- # Path from text
- text_vectors = pdb.gimp_vectors_new_from_text_layer(img, text_layer)
- pdb.gimp_image_insert_vectors(img, text_vectors, None, 0)
- # Make the layer a little bigger
- w = text_layer.width
- h = text_layer.height
- text_layer.resize(w + 10, h + 10, 5, 5)
- # New layer for the outline
- bg_layer = img.new_layer(munge(img, initstr + ' Background'))
- # Select the path created earlier
- pdb.gimp_image_select_item(img, CHANNEL_OP_REPLACE, text_vectors)
- # Same as Select -> Grow...
- pdb.gimp_selection_grow(img, outline_radius)
- # Fill in the outline
- pdb.gimp_edit_bucket_fill(bg_layer, BG_BUCKET_FILL, NORMAL_MODE,
- 100, 0, False, 0., 0.)
- # Apply the blur
- pdb.gimp_selection_all(img)
- if blur_radius > 0:
- pdb.plug_in_gauss_iir(img, bg_layer, blur_radius, True, True)
- #Move the outline layer underneath the text layer
- pdb.gimp_image_lower_item(img, img.layers[0])
- #Merge outline and text layers
- pdb.gimp_image_merge_down(img, img.layers[0], EXPAND_AS_NECESSARY)
- # Show the new image window
- gimp.displays_flush()
- # Restore the old foreground color:
- pdb.gimp_context_pop()
- # Close the undo group.
- pdb.gimp_undo_push_group_end(img)
- register(
- "python_fu_glow",
- "Text glow effect",
- "Create glow effect around text",
- "flamethrower",
- "flamethrower",
- "2017",
- "Glow...",
- "*",
- [
- (PF_IMAGE, "image", "Input image", None),
- (PF_DRAWABLE, "drawable", "Input layer", None),
- (PF_STRING, "string", "Text string", 'Hello, world!'),
- (PF_FONT, "font", "Font face", "Arial"),
- (PF_SPINNER, "size", "Font size", 16, (1, 3000, 1)),
- (PF_COLOR, "color", "Text color", (255., 255., 255.)),
- (PF_COLOR, "color", "BG color", (1.0, 0.0, 0.0)),
- (PF_SPINNER, "outline_radius", "Outline radius", 1, (1, 100, 1)),
- (PF_SPINNER, "blur_radius", "Blur radius", 3, (0, 100, 1))
- ],
- [],
- do_stuff, menu="<Image>/Filters/Alpha to Logo")
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement