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 draw_mark( image, # type: gimp.Image directions, x0, # type: int y0, # type: int size, # type: int distance # type: int ): # type: (...) -> None """Draws a mark at position where one must cut or fold the paper.""" x, y, width, height = 0, 0, 0, 0 # type: int, int, int, int for direction in directions: # type: Direction if direction == Direction.UP: x = x0 - 1 y = y0 - distance - size width = 2 height = size elif direction == Direction.DOWN: x = x0 - 1 y = y0 + distance width = 2 height = size elif direction == Direction.LEFT: x = x0 - distance - size y = y0 - 1 width = size height = 2 elif direction == Direction.RIGHT: x = x0 + distance y = y0 - 1 width = size height = 2 else: gimp.message("Invalid direction %s" % repr(direction)) return pdb.gimp_image_select_rectangle(image, gimpfu.CHANNEL_OP_REPLACE, x, y, width, height) pdb.gimp_edit_fill(image.active_layer, gimpfu.FOREGROUND_FILL) pdb.gimp_selection_none(image)
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 create_template( box_width_mm, # type: float box_height_mm, # type: float box_depth_mm # type: float ): # type: (...) -> None """Creates an empty template image given the box size.""" with DefaultContext(): box_width = mm_to_px(box_width_mm) # type: int box_height = mm_to_px(box_height_mm) # type: int box_depth = mm_to_px(box_depth_mm) # type: int xs, ys = template_coordinates(box_width, box_height, box_depth) image_width = xs[-1] - xs[0] # type: int image_height = ys[-1] - ys[0] # type: int # Create a template image with one transparent layer image = gimp.Image(image_width, image_height) # type: gimp.Image with PausedUndo(image): layer = gimp.Layer(image, "Template", image_width, image_height, gimpfu.RGBA_IMAGE, 100, gimpfu.NORMAL_MODE) # type: gimp.Layer image.add_layer(layer, 0) # Create guides for x in xs: # type: int image.add_vguide(x) for y in ys: # type: int image.add_hguide(y) # Fill the areas where the graphics go with white pdb.gimp_selection_none(image) pdb.gimp_progress_pulse() pdb.gimp_image_select_rectangle(image, gimpfu.CHANNEL_OP_ADD, xs[0], ys[1], image_width, ys[3] - ys[1]) pdb.gimp_progress_pulse() pdb.gimp_image_select_rectangle(image, gimpfu.CHANNEL_OP_ADD, xs[1], ys[0], xs[2] - xs[1], image_height) pdb.gimp_edit_fill(layer, gimpfu.WHITE_FILL) pdb.gimp_selection_none(image) def put_text(text, left, right, top, bottom): """Puts some text in the center of a rectangle.""" pdb.gimp_progress_pulse() text_size = DPI / 4 # type: int text_layer = pdb.gimp_text_layer_new( image, text, "sans-serif", text_size, gimpfu.PIXELS) # type: gimp.Layer image.add_layer(text_layer, 0) move_drawable_to(text_layer, Corner.CENTER, (left + right) // 2, (top + bottom) // 2) pdb.gimp_image_merge_down(image, text_layer, gimpfu.CLIP_TO_BOTTOM_LAYER) put_text("TOP", xs[1], xs[2], ys[0], ys[1]) put_text("LEFT", xs[0], xs[1], ys[1], ys[3]) put_text("FRONT", xs[1], xs[2], ys[1], ys[3]) put_text("RIGHT", xs[2], xs[3], ys[1], ys[3]) put_text("BACK", xs[3], xs[4], ys[1], ys[3]) put_text("BOTTOM", xs[1], xs[2], ys[3], ys[4]) put_text( "Box width: %dmm (%dpx)\n" "Box height: %dmm (%dpx)\n" "Box depth: %dmm (%dpx)" % (box_width_mm, box_width, box_height_mm, box_height, box_depth_mm, box_depth), xs[0], xs[1], ys[0], ys[1]) gimp.Display(image) gimp.displays_flush()
def clear(self): pdb.gimp_edit_fill(pdb.gimp_image_active_drawable(self.img), WHITE_FILL)