def cree_background(inLayer, inLayerF, Img): """Add background to inLayer""" newlayer = pdb.gimp_layer_copy(inLayer, True) newfond = pdb.gimp_layer_copy(inLayerF, True) layername = pdb.gimp_item_get_name(inLayer) pdb.gimp_item_set_visible(newlayer, True) pdb.gimp_image_insert_layer(Img, newlayer, None, 0) pdb.gimp_image_set_active_layer(Img, inLayer) pdb.gimp_image_insert_layer(Img, newfond, None, -1) pdb.gimp_image_lower_item(Img, newfond) pdb.gimp_item_set_visible(newfond, 1) pdb.gimp_context_set_sample_transparent(True) pdb.gimp_image_select_contiguous_color(Img, CHANNEL_OP_REPLACE, newlayer, 10, 10) pdb.gimp_edit_clear(newfond) pdb.gimp_item_set_visible(inLayer, True) clipped_layer = pdb.gimp_image_merge_down(Img, inLayer, CLIP_TO_IMAGE) pdb.gimp_item_set_name(clipped_layer, layername) pdb.gimp_selection_invert(Img) pdb.gimp_context_set_foreground((117, 117, 154)) pdb.gimp_edit_fill(newlayer, FILL_FOREGROUND) floating_sel = pdb.gimp_edit_paste(newlayer, 0) pdb.gimp_layer_set_opacity(floating_sel, 70) pdb.gimp_floating_sel_anchor(floating_sel) pdb.gimp_layer_set_opacity(newlayer, 85) pdb.gimp_selection_none(Img) layerfinal = pdb.gimp_image_get_layer_by_name(Img, layername) pdb.gimp_item_set_visible(layerfinal, False)
def load_caches(args): inColorFondR, inColorFondG, inColorFondB, outDir = args.split(" ") inDir, inNameLayerFleche = GRAPH_PATH + "layers/", "layer_fleche-1.png" inColorFondR, inColorFondG, inColorFondB = int(inColorFondR), int( inColorFondG), int(inColorFondB) nb, listimg = pdb.file_glob(inDir + "*.png", 1) baseimage = pdb.gimp_image_new(10, 10, RGB) fondcolor = (inColorFondR, inColorFondG, inColorFondB) for filename in listimg: layer = pdb.gimp_file_load_layer(baseimage, filename) pdb.gimp_image_insert_layer(baseimage, layer, None, 0) pdb.gimp_image_resize_to_layers(baseimage) pdb.gimp_message("Layers chargés") pdb.gimp_selection_all(baseimage) layerfond = pdb.gimp_image_get_layers(baseimage)[1][0] layerfond = gimp.Item.from_id(layerfond) fond = pdb.gimp_layer_copy(layerfond, 1) _, _, _, xmax, ymax = pdb.gimp_selection_bounds(baseimage) pdb.gimp_item_set_name(fond, "layer_fond.png") pdb.gimp_image_insert_layer(baseimage, fond, None, 0) pdb.gimp_edit_clear(fond) pdb.gimp_image_select_round_rectangle(baseimage, CHANNEL_OP_REPLACE, 0, 0, xmax, ymax, 35, 35) pdb.gimp_selection_shrink(baseimage, 3) pdb.gimp_selection_feather(baseimage, 20) pdb.gimp_context_set_foreground(fondcolor) pdb.gimp_edit_fill(fond, FILL_FOREGROUND) pdb.gimp_image_lower_item_to_bottom(baseimage, fond) pdb.plug_in_hsv_noise(baseimage, fond, 5, 38, 63, 74) pdb.gimp_selection_none(baseimage) pdb.gimp_message("Fond créé") caches(baseimage, inNameLayerFleche, "layer_fond.png") pdb.gimp_message("Cache créé") layercache = pdb.gimp_image_get_layer_by_name(baseimage, "cache.png") layerfond = pdb.gimp_image_get_layer_by_name(baseimage, "layer_fond.png") layerfleche = pdb.gimp_image_get_layer_by_name(baseimage, inNameLayerFleche) pdb.gimp_item_set_visible(layerfond, True) pdb.gimp_image_merge_down(baseimage, layercache, CLIP_TO_IMAGE) pdb.gimp_item_set_visible(layerfleche, True) pdb.gimp_image_merge_down(baseimage, layerfleche, CLIP_TO_IMAGE) pdb.gimp_image_scale(baseimage, 900, 550) # drawable = pdb.gimp_image_get_active_drawable(baseimage) pdb.script_fu_multiple_layer_actions(baseimage, None, 0, 0, (0, 0, 0), 4, 0, 0, 0, 0, 0) pdb.gimp_message("Taille de l'image ajustée") pdb.script_fu_export_layers(baseimage, None, outDir, "~l") pdb.gimp_message("Layers enregistrés")
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 beautify_font(image, layer): org_width = layer.width org_height = layer.height # set FG Color to white foreground = (255, 255, 255) pdb.gimp_context_set_foreground(foreground) # color selection white bucket_fill(layer) # scale layer new_width = org_width * 2 new_height = org_height * 2 local_origin = 1 # 1 = True | 0 = False pdb.gimp_layer_scale(layer, new_width, new_height, local_origin) # alpha to selection operation = CHANNEL_OP_REPLACE item = layer pdb.gimp_image_select_item(image, operation, item) # bucket fill bucket_fill(layer) # scale back to normal new_width = org_width new_height = org_height local_origin = 1 # 1 = True | 0 = False pdb.gimp_layer_scale(layer, new_width, new_height, local_origin) # alpha to selection operation = CHANNEL_OP_REPLACE item = layer pdb.gimp_image_select_item(image, operation, item)
def set_colors(): pdb.gimp_context_set_foreground((255, 255, 255)) pdb.gimp_context_set_background((0, 0, 0))
def fill_with(self, color): pdb.gimp_context_set_foreground(tuple(c / 255. for c in color)) pdb.gimp_drawable_fill(self.get_drawable(), FILL_FOREGROUND)
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()