예제 #1
0
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]"
예제 #2
0
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 caches(inImg, inNameLayerFleche, inNameLayerFond):
    path_cadenas = GRAPH_PATH + "images/cadenas.png"
    imagecadenas = pdb.gimp_file_load(path_cadenas, path_cadenas)
    layercadenas = pdb.gimp_image_get_active_layer(imagecadenas)

    pdb.gimp_selection_all(imagecadenas)
    pdb.gimp_edit_copy(layercadenas)
    pdb.gimp_image_delete(imagecadenas)

    layerfond = pdb.gimp_image_get_layer_by_name(inImg, inNameLayerFond)
    layerfleche = pdb.gimp_image_get_layer_by_name(inImg, inNameLayerFleche)
    _, alayers = pdb.gimp_image_get_layers(inImg)

    for layercurrent in alayers:
        pdb.gimp_selection_none(inImg)
        layercurrent = gimp.Item.from_id(layercurrent)
        pdb.script_fu_add_bevel(inImg, layercurrent, 5, 0, 0)

        pdb.gimp_item_set_visible(layercurrent, False)
        layername = pdb.gimp_item_get_name(layercurrent)
        if not (layername == inNameLayerFleche
                or layername == inNameLayerFond):
            cree_background(layercurrent, layerfond, inImg)

    cache = pdb.gimp_image_merge_visible_layers(inImg, CLIP_TO_IMAGE)
    pdb.script_fu_add_bevel(inImg, cache, 5, 0, 0)
    pdb.gimp_item_set_name(cache, "cache.png")

    pdb.gimp_image_lower_item_to_bottom(inImg, layerfleche)
    pdb.gimp_image_lower_item_to_bottom(inImg, cache)
    pdb.gimp_image_lower_item_to_bottom(inImg, layerfond)
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)
예제 #5
0
def rotate(layer, angle):
    """ rotate a layer """
    pdb.gimp_edit_copy(layer)
    tmp_image = pdb.gimp_edit_paste_as_new()

    tmp_layer = pdb.gimp_image_get_active_layer(tmp_image)
    pdb.gimp_item_transform_rotate(tmp_layer, angle, False,
                                   tmp_layer.width / 2, tmp_layer.height / 2)
    print(tmp_layer.width, tmp_layer.height)
    pdb.gimp_image_resize(tmp_image, tmp_layer.width, tmp_layer.height, 0, 0)
    pdb.gimp_layer_set_offsets(tmp_layer, 0, 0)

    pdb.gimp_display_new(tmp_image)
    pdb.gimp_displays_flush()
예제 #6
0
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)
예제 #7
0
def copy_all(image, drawable):
    # select all
    pdb.gimp_selection_all(image)

    # copy
    non_empty = pdb.gimp_edit_copy(drawable)
    if not non_empty:
        pdb.gimp_message("Error: Copy operation failed")
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)
예제 #9
0
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]"
예제 #10
0
    def __copyForegroundImageIntoBuffer(self):
        """
		Instruct GIMP to copy the foreground image into its buffer.


		Parameters:

		NA


		Returns:

		NA


		Invoked by :

		OverlayImageAgent.__copyAndPasteForegroundImage
		OverlayImageAgent.__copyAndPasteForegroundImageAsNew
		OverlayImageAgent.__copyAndPasteForegroundImageIntoNewLayer


		Invokes :

		OverlayImageAgent.__pauseAndProgressDisplay
		"""

        nameProcedure = "OverlayImageAgent::__copyForegroundImageIntoBuffer"

        print("%s : Enter" % (nameProcedure))

        # Copy the Foreground Image into the Buffer.

        copy_result = pdb.gimp_edit_copy(self.drawable_foreground)

        print("%s : Copy result = %s" % (nameProcedure, str(copy_result)))

        # Update the Progress Bar in the Plugin Window.

        gimp.progress_init("Have copied foreground image into Buffer")

        self.__pauseAndProgressDisplay(self.sleep_timer)
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)
예제 #12
0
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)
예제 #13
0
    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)
예제 #14
0
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))
예제 #15
0
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))