def python_runway(img, layer): if not layer.is_rgb: raise ValueError("Expected RGB layer") # because pdb cannot save to a buffer, we have to use a temporary file instead f = tempfile.NamedTemporaryFile(suffix=".png", delete=False) f.close() pdb.file_png_save(img, layer, f.name, f.name, 0, 9, 0, 0, 0, 0, 0) # convert data from file to base64 encoded bytes data = open(f.name, "rb").read() b64 = base64.b64encode(data) os.unlink(f.name) # send data to Runway via a POST request data = json.dumps({"semantic_map": b64}) req = urllib2.Request("http://localhost:8000/query", data, {"Content-Type": "application/json"}) f = urllib2.urlopen(req) resp = json.loads(f.read()) f.close() # save result to a temporary file, because pdb cannot load from a buffer jpg = base64.b64decode(resp["output"][22:]) f = tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) f.close() open(f.name, "wb").write(jpg) # open the temp file image = pdb.gimp_file_load(f.name, f.name) # copy the first layer to clipboard pdb.gimp_edit_copy(image.layers[0]) os.unlink(f.name) # paste clipboard contents as a floating selection floating = pdb.gimp_edit_paste(layer, 0) floating.name = layer.name + " [Runway]"
def python_animation_from_videocaps(image, drawable, fps=24, reduce_by=4, text_mode='none', text_layer=None): """The plugin's main function.""" gimpfu.gimp.progress_init('Working on frames...') # Reduce frames delay = int(1000 / fps * reduce_by) for i, layer in enumerate(image.layers[:]): if i % reduce_by == 0: layer.name = '%s (%sms)' % (layer.name, delay) else: pdb.gimp_image_remove_layer(image, layer) gimpfu.gimp.progress_update(0.5) # Add text if text_mode != 'none' and text_layer.image == image: pdb.gimp_layer_resize_to_image_size(text_layer) pdb.gimp_edit_copy(text_layer) layers = image.layers[::2] if text_mode == 'blink' else image.layers for i, layer in enumerate(layers): selection = pdb.gimp_edit_paste(layer, True) pdb.gimp_floating_sel_anchor(selection) pdb.gimp_image_remove_layer(image, text_layer) gimpfu.gimp.progress_update(1)
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 stack(target=None): for image in gimp.image_list(): pdb.gimp_selection_none(image) if image.layers: if not target: target = image elif image != target: for layer in image.layers: pdb.gimp_edit_cut(layer) floating = pdb.gimp_edit_paste(target.layers[0], True) pdb.gimp_floating_sel_to_layer(floating)
def change_num(image, inNumero): layer = pdb.gimp_image_get_active_layer(image) pdb.gimp_context_set_sample_transparent(True) pdb.gimp_image_select_contiguous_color(image, CHANNEL_OP_REPLACE,layer, 1, 1) pdb.gimp_selection_invert(image) _, x, y, x2, y2 = pdb.gimp_selection_bounds(image) xthird=x + ((x2 - x) // 4 * 3) y = _find_black_not_transparent(image, layer, xthird, y) pdb.gimp_context_set_sample_transparent(False) pdb.gimp_image_select_contiguous_color(image, CHANNEL_OP_REPLACE, layer, xthird, y) pdb.gimp_edit_clear(layer) if inNumero > 1: _, x, y, x2, y2 = pdb.gimp_selection_bounds(image) ymiddle = y + ( (y2 - y) // 2) keep = True while keep: if not _is_transparent(image, layer, x, ymiddle): keep = False pdb.gimp_context_set_sample_transparent(False) pdb.gimp_context_set_sample_threshold(1) pdb.gimp_image_select_contiguous_color(image, CHANNEL_OP_REPLACE, layer, x+1, ymiddle) pdb.gimp_context_set_sample_threshold(0.1) x += 1 pdb.gimp_edit_clear(layer) _, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image) pdb.gimp_image_select_rectangle(image, CHANNEL_OP_REPLACE, x1, y1, x2-x1, y2-y1) filename = GRAPH_PATH + str(inNumero) + ".png" imagechiffre = pdb.gimp_file_load(filename, filename) layerchiffre = pdb.gimp_image_get_active_layer(imagechiffre) pdb.gimp_selection_all(imagechiffre) pdb.gimp_edit_copy(layerchiffre) pdb.gimp_image_delete(imagechiffre) floating_sel = pdb.gimp_edit_paste(layer,False) pdb.gimp_floating_sel_anchor(floating_sel)
def mirror(image=None): if not image: image = gimp.image_list()[0] max_layer = 0 for layer in image.layers: try: if int(layer.name) > max_layer: max_layer = int(layer.name) except ValueError: pass layers_to_reverse = image.layers[1:] pdb.gimp_selection_none(image) for layer in layers_to_reverse: pdb.gimp_edit_copy(layer) floating = pdb.gimp_edit_paste(image.layers[0], True) pdb.gimp_floating_sel_to_layer(floating) max_layer += 1 floating.name = str(max_layer)
def paste_in_new_image(image2, ilayer, width, height, offx, offy): # create a new layer in the second image type = RGBA_IMAGE name = "information text {}".format(ilayer + 1) opacity = 100 mode = NORMAL_MODE layer_info = pdb.gimp_layer_new(image2, width, height, type, name, opacity, mode) position = 0 pdb.gimp_image_add_layer(image2, layer_info, position) # paste image drawable = image2.layers[0] paste_into = True floating_sel = pdb.gimp_edit_paste(drawable, paste_into) pdb.gimp_floating_sel_anchor(floating_sel) # move to original visor position pdb.gimp_layer_set_offsets(drawable, offx, offy)
def copy_and_rotate_rectangle( src_image, # type: gimp.Image src_x, # type: int src_y, # type: int src_width, # type: int src_height, # type: int dst_layer, # type: gimp.Layer dst_x, # type: int dst_y, # type: int dst_corner, # type: Corner angle # type: int ): # type: (...) -> None """Copies a rectangular region from one image to another while also rotating it. """ pdb.gimp_image_select_rectangle(src_image, gimpfu.CHANNEL_OP_REPLACE, src_x, src_y, src_width, src_height) pdb.gimp_edit_copy_visible(src_image) pdb.gimp_selection_none(src_image) # Paste into dst as a floating selection floating = pdb.gimp_edit_paste(dst_layer, gimpfu.TRUE) # type: gimp.Layer # Rotate floating selection if needed angles = { 90: gimpfu.ROTATE_90, 180: gimpfu.ROTATE_180, 270: gimpfu.ROTATE_270 } # type: int if angle in angles: rotation = angles[angle] # type: int pdb.gimp_drawable_transform_rotate_simple(floating, rotation, gimpfu.FALSE, 0, 0, gimpfu.FALSE) # Move floating selection into position and anchor it move_drawable_to(floating, dst_corner, dst_x, dst_y) pdb.gimp_floating_sel_anchor(floating)
def python_gaugan(img, layer, style="random"): if not layer.is_rgb: raise ValueError("Expected RGB layer") # because pdb cannot save to a buffer, we have to use a temporary file instead f = tempfile.NamedTemporaryFile(suffix=".png", delete=False) f.close() pdb.file_png_save(img, layer, f.name, f.name, 0, 9, 0, 0, 0, 0, 0) data = open(f.name, "rb").read() os.unlink(f.name) # send to GauGAN API gaugan = GauganAPI() jpg = gaugan.convert(data, style) # save result to a temporary file, because pdb cannot load from a buffer f = tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) f.close() open(f.name, "wb").write(jpg) # open the temp file image = pdb.gimp_file_load(f.name, f.name) # copy the first layer to clipboard pdb.gimp_edit_copy(image.layers[0]) os.unlink(f.name) # paste clipboard contents as a floating selection floating = pdb.gimp_edit_paste(layer, 0) floating.name = layer.name + " [GauGAN]"
def sheet(image=None, cols=0): if not image: image = gimp.image_list()[0] if not cols: best = (1, 10000000) for cols in range(1, len(image.layers) + 1): rows = (len(image.layers) + (cols - 1)) // cols (sheet_width, sheet_height) = (cols * image.width, rows * image.height) sheet_aspect_ratio = sheet_width / sheet_height if sheet_width > sheet_height else sheet_height / sheet_width if sheet_aspect_ratio < best[1]: best = (cols, sheet_aspect_ratio) cols = best[0] file_path = "{}_sheet_{}_frames_{}_columns_{}x{}.png".format( pdb.gimp_image_get_filename(image)[:-4], len(image.layers), cols, image.width, image.height) gimp.progress_init("Save sheet as {}".format(file_path)) rows = (len(image.layers) + (cols - 1)) // cols sheet = pdb.gimp_image_new(image.width * cols, image.height * rows, 0) try: sheet_layer = pdb.gimp_layer_new( sheet, sheet.width, sheet.height, 1, # type = RGBA-IMAGE "sprite sheet", 100, # opacity = 100 % 0 # mode = LAYER-MODE-NORMAL-LEGACY ) pdb.gimp_image_insert_layer(sheet, sheet_layer, None, 0) (row, col) = (0, 0) for (layer_index, layer) in enumerate(image.layers): pdb.gimp_selection_none(image) pdb.gimp_layer_resize_to_image_size(layer) pdb.gimp_edit_copy(layer) floating = pdb.gimp_edit_paste(sheet_layer, True) (left, top) = floating.offsets pdb.gimp_layer_translate(floating, col * image.width - left, row * image.height - top) pdb.gimp_floating_sel_anchor(floating) col += 1 if col >= cols: col = 0 row += 1 gimp.progress_update(100 * (layer_index + 1) / len(image.layers)) pdb.file_png_save( sheet, sheet_layer, file_path, None, True, # interlace 9, # compression True, # bkgd True, # gama True, # offs True, # phys True, # time ) gimp.message("All frames saved as {}".format(file_path)) finally: pdb.gimp_image_delete(sheet)
def halftone_gimp(img, layer, slide_density, slide_circle_size, work_size_flag, work_size_width, revert_size_flag, black_strength, slide_angle): # Obtain layer dimensions. width = layer.width height = layer.height print("original size:", width, height) print("density", slide_density) D = int(slide_density) print("circle size", "slide_circle_size") C = int(slide_circle_size) print("black strength", black_strength) B = int(black_strength) ANGLES = POSSIBLE_ANGLES[int(slide_angle) - 1] print("angles", ANGLES) # New image dimensions if work_size_flag is True: new_width = int(work_size_width) new_height = int(height * (new_width / float(width))) print("new_size:", new_width, new_height) scale_image(img, new_width, new_height) else: new_width = width new_height = height add_cmyk_layers(img, layer) halftone_layers = [None] * 4 for k in range(0, 4): current_layer = find_layer(img, COMPONENT_STRING[k]) rotate_layer(current_layer, ANGLES[k]) halftone_layers[k] = pdb.gimp_layer_new( img, current_layer.width, current_layer.height, RGBA_IMAGE, COMPONENT_STRING[k] + " halftone", 100, MULTIPLY_MODE) pdb.gimp_image_insert_layer(img, halftone_layers[k], None, 0) pdb.gimp_drawable_fill(halftone_layers[k], FILL_WHITE) start = timer() halftone_layer(img, current_layer, halftone_layers[k], D, COLORS[k], C, B) end = timer() print("halftone in ", end - start) rotate_layer(halftone_layers[k], -ANGLES[k]) x0, y0 = pdb.gimp_drawable_offsets(halftone_layers[k]) non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(img) print(x0, y0) print(x1, y1, x2, y2) xx = new_width / 2 - current_layer.width / 2 yy = new_height / 2 - current_layer.height / 2 # print xx, yy pdb.gimp_layer_set_offsets(halftone_layers[k], x0 + xx, y0 + yy) for i_layer in COMPONENT_STRING: del_layer = find_layer(img, i_layer) img.remove_layer(del_layer) for i_layer in img.layers: if i_layer.name.endswith("halftone"): i_layer.visible = False # if revert_size_flag is True: # scale_image(img, width, height) else: i_layer.visible = False for i_layer in img.layers: if i_layer.name.endswith("halftone"): current_layer = pdb.gimp_layer_new(img, new_width, new_height, RGBA_IMAGE, "_" + i_layer.name + "_", 100, MULTIPLY_MODE) pdb.gimp_image_insert_layer(img, current_layer, None, 0) pdb.gimp_rect_select(img, 0, 0, new_width, new_height, 2, 0, 0) pdb.gimp_edit_copy(i_layer) new_layer = pdb.gimp_edit_paste(current_layer, True) pdb.gimp_floating_sel_anchor(new_layer) for i_layer in img.layers: if i_layer.name.endswith("halftone"): print(i_layer.name) img.remove_layer(i_layer) if revert_size_flag is True: scale_image(img, width, height)
def overlayImage(self): nameMethod = self.nameClass + "::overlayImage" imageBackground_new = None imageForeground_new = None drawableBackground_new = None drawableForeground_new = None print("%s : Enter" % (nameMethod)) copyResult = pdb.gimp_edit_copy(self.drawableForeground) print("%s : Copy result = %s" % (nameMethod, str(copyResult))) # pdb.gimp_drawable_update(drawable, horizontalLocation, verticalLocation, 384, 216) # The following operation should paste the image which is in the buffer, into a new layer of the # background image. gimp.progress_init("Overlaying one image onto another") if (True): pdb.gimp_edit_paste(self.drawableBackground, True) # imageBackground_new = self.imageBackground else: imageBackground_new = pdb.gimp_edit_paste_as_new( self.drawableBackground, True) if (imageBackground_new == -1): print( "%s : Attempted to paste from the Edit buffer, but it appears to be empty." % (nameMethod)) raise Exception( "\n\nAn Exception has been raised by the method;\n\n " + nameMethod + "\n\nThis method attempted to paste from the Edit buffer, but it appears to be empty.\n\nAs a result, this Plugin is about to terminate!" ) # self.drawableNew = pdb.gimp_image_get_active_layer(self.imageNew) # Flatten the modified background image down into one layer. drawableBackground_new = pdb.gimp_image_flatten(self.imageBackground) # self.drawableBackground = drawableBackground_new # Copy and paste the background image into the foreground image. copyResult = pdb.gimp_edit_copy(drawableBackground_new) pdb.gimp_edit_paste(self.drawableForeground, True) self.drawableForeground = pdb.gimp_image_flatten(self.imageForeground)
def simple_plugin(filename_background, filename_foreground, filename_result): nameProcedure = "simple_plugin" sleep_timer = 0 counter = 1 print("%s : Enter" % (nameProcedure)) # ---------------------------------------------------------------------------------------------- # Get the following from both the background and foreground image files; # # - image # - drawable # ---------------------------------------------------------------------------------------------- image_background = pdb.gimp_file_load(filename_background, filename_background) drawable_background = pdb.gimp_image_get_active_layer(image_background) image_foreground = pdb.gimp_file_load(filename_foreground, filename_foreground) drawable_foreground = pdb.gimp_image_get_active_layer(image_foreground) display_diagnostics(counter, image_background, image_foreground, drawable_background, drawable_foreground) counter = counter + 1 gimp.progress_init("Have got image and drawable from both files") time.sleep(sleep_timer) # ---------------------------------------------------------------------------------------------- # Start a GIMP Undo group, as this will allow the actions of this Plugin to be undone in one # step. # ---------------------------------------------------------------------------------------------- pdb.gimp_image_undo_group_start(image_background) # ---------------------------------------------------------------------------------------------- # Copy the foreground image. # ---------------------------------------------------------------------------------------------- copy_result = pdb.gimp_edit_copy(drawable_foreground) print("%s : Copy result = %s" % (nameProcedure, str(copy_result))) gimp.progress_init("Have copied foreground image into Buffer") time.sleep(sleep_timer) # ---------------------------------------------------------------------------------------------- # Paste the foreground image onto the background image. # ---------------------------------------------------------------------------------------------- use_gimp_edit_paste_as_new = False if use_gimp_edit_paste_as_new: pdb.gimp_edit_paste(drawable_background, True) else: image_background_new = pdb.gimp_edit_paste_as_new( drawable_background, True) if (image_background_new == -1): print( "%s : Attempted to paste from the Edit buffer, but it appears to be empty." % (nameProcedure)) exception_message = "\n\nAn Exception has been raised by the method;\n\n " + \ nameProcedure + \ "\n\nThis method attempted to paste from the Edit buffer, but it appears to be empty.\n\nAs a result, this Plugin is about to terminate!" raise Exception(exception_message) gimp.progress_init( "Have pasted foreground image from Buffer onto background image") time.sleep(sleep_timer) display_diagnostics(counter, image_background, image_foreground, drawable_background, drawable_foreground) counter = counter + 1 # ---------------------------------------------------------------------------------------------- # Flatten the modified background image down into one layer. # ---------------------------------------------------------------------------------------------- drawable_background = pdb.gimp_image_flatten(image_background) gimp.progress_init("Have flattened the background image") time.sleep(sleep_timer) display_diagnostics(counter, image_background, image_foreground, drawable_background, drawable_foreground) # ---------------------------------------------------------------------------------------------- # Save the background image into a specified file. # ---------------------------------------------------------------------------------------------- if use_gimp_edit_paste_as_new: pdb.gimp_file_save(image_background, drawable_background, filename_result, filename_result) else: pdb.gimp_file_save(image_background_new, drawable_background, filename_result, filename_result) gimp.progress_init("Have saved the background image") time.sleep(sleep_timer) # ---------------------------------------------------------------------------------------------- # End the GIMP Undo group which was started at the beginning of this Plugin. # ---------------------------------------------------------------------------------------------- pdb.gimp_image_undo_group_end(image_background) # ---------------------------------------------------------------------------------------------- # Close the GIMP images now that we have finished with them, otherwise they will use up memory # nnecessarily. # ---------------------------------------------------------------------------------------------- pdb.gimp_image_delete(image_foreground) pdb.gimp_image_delete(image_background) print("%s : Exit" % (nameProcedure))
def \ superimpose_image_over_another_noninteractive( # image, # drawable, list_filenames, list_filenames_superimpose # horizontalLocation, # verticalLocation ) : nameFunction = "superimpose_image_over_another_interactive" print("----------------------------------------") print("%s : Enter" % (nameFunction)) IFS = ";" # listFiles = fileContents.split(IFS) listFiles = list_filenames.split(IFS) listFiles_superimpose = list_filenames_superimpose.split(IFS) print("%s : Number of elements in list = %d" % (nameFunction, len(listFiles))) print("%s : File list = %s" % (nameFunction, listFiles)) print("%s : Number of elements in list = %d" % (nameFunction, len(listFiles_superimpose))) print("%s : File list = %s" % (nameFunction, listFiles_superimpose)) if (len(listFiles) == 0): print("%s : Number of background image files = 0 : a") % (nameFunction) # errdialog = gtk.MessageDialog( # None, # 0, # gtk.MESSAGE_ERROR, # gtk.BUTTONS_OK, # "A) You must specify at least one background image file." # ) # errdialog.show_all() # errdialog.run() # raise Exception("You must specify at least one background image file.") elif (len(listFiles_superimpose) == 0): gimp.message( "B) You must specify at least one superimpose image file.") print("%s : Number of superimpose image files = 0 : a") % ( nameFunction) # raise Exception("You must specify at least one superimpose image file.") # elif (len(listFiles) == 1) : and elif (listFiles[0] == ''): gimp.message("C) You must specify at least one background image file.") print("%s : Number of background image files = 0 : b") % (nameFunction) # raise Exception("You must specify at least one background image file.") # elif (len(listFiles_superimpose) == 1) and elif (listFiles_superimpose[0] == ''): gimp.message( "D) You must specify at least one superimpose image file.") print("%s : Number of superimpose image files = 0 : b") % ( nameFunction) # raise Exception("You must specify at least one superimpose image file.") elif len(listFiles) != len(listFiles_superimpose): gimp.message( "E) The number of files specified must be the same for both background and superimpose images." ) print( "%s : The number of files specified must be the same for both background and superimpose images!" ) % (nameFunction) # raise Exception("The number of files specified must be the same for both background and superimpose images!") indexList = 0 for filename in listFiles: indexList = indexList + 1 print("%s : ========================================" % (nameFunction)) print("%s : Filename = %s" % (nameFunction, filename)) print("%s : ========================================" % (nameFunction)) if (not path.isfile(filename)): print("%s : > is NOT a file" % (nameFunction)) continue filename_superimpose = listFiles_superimpose[indexList - 1] print("%s : ========================================" % (nameFunction)) print("%s : Filename of image to superimpose = %s" % (nameFunction, filename_superimpose)) print("%s : ========================================" % (nameFunction)) if (not path.isfile(filename_superimpose)): print("%s : > is NOT a file" % (nameFunction)) gimp.progress_init("Superimposing one image over the other") image = pdb.gimp_file_load(filename, filename) drawable = pdb.gimp_image_get_active_layer(image) # Start a GIMP Undo group, as this will allow the actions of this Plugin to be undone in one step. pdb.gimp_undo_push_group_start(image) widthImage = image.width heightImage = image.height widthDrawable = drawable.width heightDrawable = drawable.height print("Width image = %s" % widthImage) print("Height image = %s" % heightImage) print("Width drawable = %s" % widthDrawable) print("Height drawable = %s" % heightDrawable) # print("Horizontal location = %s" % horizontalLocation) # print("Vertical location = %s" % verticalLocation) print("Image filename = %s" % image.filename) # Open the image file to be superimposed and get its drawable object. image_super = pdb.gimp_file_load(filename_superimpose, filename_superimpose) drawable_super = pdb.gimp_image_get_active_layer(image_super) print("Width super image = %s" % image_super.width) print("Height super image = %s" % image_super.height) print("Width super drawable = %s" % drawable_super.width) print("Height super drawable = %s" % drawable_super.height) # How many layers does the current image now contain? # # Use gimp-edit-copy and gimp-edit-paste? copy_result = pdb.gimp_edit_copy(drawable_super) if (copy_result == True): print("True") else: print("False") print("Selection copy result = %s" % copy_result) # pdb.gimp_drawable_update(drawable, horizontalLocation, verticalLocation, 384, 216) # The following operation should paste the image which is in the buffer, into a new layer of the # original image. pdb.gimp_edit_paste(drawable, True) widthImage = image.width heightImage = image.height widthDrawable = drawable.width heightDrawable = drawable.height print("Width image = %s" % widthImage) print("Height image = %s" % heightImage) print("Width drawable = %s" % widthDrawable) print("Height drawable = %s" % heightDrawable) # print("Horizontal location = %s" % horizontalLocation) # print("Vertical location = %s" % verticalLocation) # Move the # pdb.gimp_drawable_update() drawable_new = pdb.gimp_image_flatten(image) pdb.gimp_file_save(image, drawable_new, filename, filename) # End the GIMP Undo group. pdb.gimp_undo_push_group_end(image) # Close the image now that we have finished with it, otherwise it will use up memory unnecessarily. pdb.gimp_image_delete(image) # End of for loop. print("%s : Exit" % (nameFunction))
def __copyAndPasteForegroundImage(self): """ Paste the foreground image onto the background image. Instruct GIMP to copy the forground image into its buffer, then paste the contents of this buffer into the background image. Parameters: NA Returns: NA Invoked by : OverlayImageAgent.__run Invokes : OverlayImageAgent.__copyForegroundImageIntoBuffer """ nameProcedure = "OverlayImageAgent::__copyAndPasteForegroundImage" print("%s : Enter" % (nameProcedure)) # Copy the Foreground Image into the Buffer. self.__copyForegroundImageIntoBuffer() # Paste the Foreground Image from the Buffer onto the Background Image. # # This operation will add a new Layer to the Image. # # self.image_background_new will be of type gimp.Layer [num_layers, list_layer_ids] = pdb.gimp_image_get_layers(self.image_background) print("%s : Number of layers in Background Image = %d" % (nameProcedure, num_layers)) print("%s : Filename Background Image = %s" % (nameProcedure, self.image_background.filename)) floating_selection = pdb.gimp_edit_paste(self.drawable_background, True) if (floating_selection == -1): print( "%s : Attempted to paste from the Edit buffer, but it appears to be empty." % (nameProcedure)) exception_message = "\n\nAn Exception has been raised by the method;\n\n " + \ nameProcedure + \ "\n\nThis method attempted to paste from the Edit buffer, but it appears to be empty.\n\nAs a result, this Plugin is about to terminate!" raise Exception(exception_message) pdb.gimp_floating_sel_anchor(floating_selection) [num_layers, list_layer_ids] = pdb.gimp_image_get_layers(self.image_background) print("%s : Number of layers in Background Image = %d" % (nameProcedure, num_layers)) # Update the Progress Bar in the Plugin Window. gimp.progress_init( "Have pasted Foreground Image from Buffer onto Background Image") print("%s : Exit" % (nameProcedure))