def add_black_outline(image, drawable, original_layer_position, width, height, offx, offy): # make selection bigger steps = 3 pdb.gimp_selection_grow(image, steps) # create new layer type = RGBA_IMAGE name = "text background" opacity = 100 mode = NORMAL_MODE layer_textbg = pdb.gimp_layer_new(image, width, height, type, name, opacity, mode) position = original_layer_position + 1 pdb.gimp_image_add_layer(image, layer_textbg, position) #offset new layer by info pdb.gimp_layer_set_offsets(layer_textbg, offx, offy) # select layer image.active_layer = layer_textbg # set FG Color to black foreground = (0, 0, 0) pdb.gimp_context_set_foreground(foreground) # fill selection with black fill_mode = FG_BUCKET_FILL paint_mode = NORMAL_MODE opacity = 100 threshold = 0 sample_merged = 0 x = 0 y = 0 pdb.gimp_bucket_fill(layer_textbg, fill_mode, paint_mode, opacity, threshold, sample_merged, x, y) # select the text layer and merge it to the black outline merge_layer = image.layers[original_layer_position] merge_type = EXPAND_AS_NECESSARY layer = pdb.gimp_image_merge_down(image, merge_layer, merge_type) return layer
def python_text_border(image, drawable, thickness=5, colour=(0, 0, 0)): """The plugin's main function.""" text_layer = image.active_layer layer_name = text_layer.name pdb.gimp_image_select_item(image, 2, text_layer) pdb.gimp_selection_grow(image, thickness) border_layer = gimp.Layer( image, 'border', image.width, image.height, gimpfu.RGBA_IMAGE, 100, gimpfu.NORMAL_MODE) position = pdb.gimp_image_get_layer_position(image, text_layer) image.add_layer(border_layer, position + 1) old_fg = gimp.get_foreground() gimp.set_foreground(colour) pdb.gimp_edit_fill(border_layer, gimpfu.FOREGROUND_FILL) gimp.set_foreground(old_fg) layer = pdb.gimp_image_merge_down(image, text_layer, 0) pdb.gimp_layer_set_name(layer, layer_name)
def stickerify_bordure(image, current_layer, black_grow=3, white_grow=12, shadow=True, canvas_increase=0, resize=False): def duplicate_layer(): copy = current_layer.copy() image.add_layer(copy) # copy is added above so we want to go down a bit image.active_layer = current_layer return copy def fill_black(): pdb.gimp_edit_bucket_fill(current_layer, 1, 0, 100, 255, 0, 0, 0) def fill_white(): pdb.gimp_edit_bucket_fill(current_layer, 0, 0, 100, 255, 0, 0, 0) def set_colors(): pdb.gimp_context_set_foreground((255, 255, 255)) pdb.gimp_context_set_background((0, 0, 0)) pdb.gimp_context_push() pdb.gimp_image_undo_group_start(image) # clean selection to avoid bugs pdb.gimp_selection_none(image) set_colors() # resize early to avoid compressing the bordure if resize: width, height = image.width, image.height if width == height: new_width, new_height = 512, 512 elif width > height: new_width, new_height = 512, int(height * (512.0 / width)) elif width < height: new_width, new_height = int(width * (512.0 / height)), 512 pdb.gimp_image_scale(image, new_width, new_height) if canvas_increase: width, height = image.width, image.height width_increase = int(width * (canvas_increase / 100)) height_increase = int(height * (canvas_increase / 100)) pdb.gimp_image_resize(image, width + width_increase, height + height_increase, int(width_increase / 2), int(height_increase / 2)) pdb.gimp_layer_resize_to_image_size(current_layer) duplicate_layer() # alpha to selection pdb.gimp_image_select_item(image, 0, current_layer) pdb.gimp_selection_grow(image, black_grow) fill_black() second_layer = duplicate_layer() pdb.gimp_selection_grow(image, white_grow) fill_white() if shadow: duplicate_layer() fill_black() current_layer.translate(8, 8) pdb.gimp_selection_all(image) pdb.plug_in_gauss(image, current_layer, 20, 20, 0) pdb.gimp_layer_set_opacity(current_layer, 70) pdb.gimp_image_merge_down(image, second_layer, 0) if shadow: pdb.gimp_image_merge_down(image, image.active_layer, 0) pdb.gimp_layer_set_name(image.active_layer, "Sticker bordure") pdb.gimp_selection_none(image) pdb.gimp_image_undo_group_end(image) pdb.gimp_context_pop() pdb.gimp_displays_flush()
def stickerify_bordure(image, tdrawable, black_grow=3, white_grow=12, shadow=True): def duplicate_layer(): copy = current_layer.copy() image.add_layer(copy) # copy is added above so we want to go down a bit image.active_layer = current_layer return copy def fill_black(): pdb.gimp_edit_bucket_fill(current_layer, 1, 0, 100, 255, 0, 0, 0) def fill_white(): pdb.gimp_edit_bucket_fill(current_layer, 0, 0, 100, 255, 0, 0, 0) def set_colors(): pass pdb.gimp_context_push() pdb.gimp_image_undo_group_start(image) pdb.gimp_context_set_foreground((255, 255, 255)) pdb.gimp_context_set_background((0, 0, 0)) set_colors() current_layer = image.active_layer duplicate_layer() # alpha to selection pdb.gimp_image_select_item(image, 0, current_layer) pdb.gimp_selection_grow(image, black_grow) fill_black() second_layer = duplicate_layer() pdb.gimp_selection_grow(image, white_grow) fill_white() if shadow: duplicate_layer() fill_black() current_layer.translate(8, 8) pdb.gimp_selection_all(image) pdb.plug_in_gauss(image, current_layer, 20, 20, 0) pdb.gimp_layer_set_opacity(current_layer, 70) pdb.gimp_image_merge_down(image, second_layer, 0) if shadow: pdb.gimp_image_merge_down(image, image.active_layer, 0) pdb.gimp_image_undo_group_end(image) pdb.gimp_context_pop() pdb.gimp_displays_flush()