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)
示例#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 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)
示例#4
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)
示例#5
0
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)
示例#6
0
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 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)
示例#8
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)
    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))