def layer_replay_images(imageFiles, delayMultiplier=1):
    """Joins imageFiles as delayed layers."""
    layeredImage, currentFile = gimp.Image(1, 1, RGB), next(imageFiles)
    currentLayer = pdb.gimp_file_load_layer(layeredImage, currentFile)
    layeredImage.resize(currentLayer.width, currentLayer.height, 0, 0)
    for nextFile in imageFiles:
        Delay = identify_delay(currentFile, nextFile) * delayMultiplier
        insert_layer(layeredImage, currentLayer, Delay)
        currentFile = nextFile
        currentLayer = pdb.gimp_file_load_layer(layeredImage, currentFile)
    else:
        insert_layer(layeredImage, currentLayer, Delay * 4)
    return layeredImage 
Пример #2
0
def prepare_tts(img, _, output_folder):  # pylint: disable=R0914
    """ Prepare a TTS sheet image.
    """
    gimp.progress_init('Prepare a TTS sheet image...')
    pdb.gimp_undo_push_group_start(img)

    try:
        file_name, _ = _get_filename_backside(img, 'jpg')
    except Exception:  # pylint: disable=W0703
        pdb.gimp_undo_push_group_end(img)
        return

    parts = file_name.split('_')
    num = int(parts[-3])
    rows = int(parts[-4])
    columns = int(parts[-5])
    new_width = columns * 750
    new_height = rows * 1050
    pdb.gimp_image_scale(img, new_width, new_height)

    json_path = re.sub(r'\.jpg$', '.json', pdb.gimp_image_get_filename(img))
    try:
        with open(json_path, 'r') as fobj:
            cards = json.load(fobj)
    except Exception:  # pylint: disable=W0703
        pdb.gimp_undo_push_group_end(img)
        return

    cards = [c['path'] for c in cards]
    if len(cards) != num:
        pdb.gimp_undo_push_group_end(img)
        return

    card_rows = [
        cards[i * columns:(i + 1) * columns]
        for i in range((len(cards) + columns - 1) // columns)
    ]
    if len(card_rows) != rows:
        pdb.gimp_undo_push_group_end(img)
        return

    for i, card_row in enumerate(card_rows):
        for j, card_path in enumerate(card_row):
            if not os.path.exists(card_path):
                pdb.gimp_undo_push_group_end(img)
                return

            card_layer = pdb.gimp_file_load_layer(img, card_path)
            pdb.gimp_image_insert_layer(img, card_layer, None, -1)
            rotation = _get_rotation(card_layer)
            if rotation:
                _rotate(card_layer, True)

            pdb.gimp_layer_set_offsets(card_layer, j * 750, i * 1050)
            pdb.gimp_image_merge_down(img, card_layer, 1)

    pdb.file_jpeg_save(img, img.layers[0],
                       os.path.join(output_folder, file_name), file_name, 1, 0,
                       1, 0, '', 2, 1, 0, 0)
    pdb.gimp_undo_push_group_end(img)
def layer_images(imageFiles):
    """Joins imageFiles as layers."""
    initialFile = next(imageFiles)
    layeredImage = pdb.gimp_file_load(initialFile, initialFile)
    for imageFile in imageFiles:
        newLayer = pdb.gimp_file_load_layer(layeredImage, imageFile)
        pdb.gimp_image_insert_layer(layeredImage, newLayer, None, 0)
    return layeredImage 
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 createTechIcons(timg, tdrawable,file,folder, outFolder,scaleTo):
  for fileName in os.listdir(folder):
    # backGroundImage=pdb.gimp_file_load(file, file)
    # backGroundLayer=backGroundImage.layers[0]
    if fileName[-4:]!=".dds":
      continue
    outFile=outFolder+"/"+"tech_"+fileName
    image=pdb.gimp_file_load(folder+"/"+fileName, folder+"/"+fileName)
    pdb.gimp_image_scale(image,scaleTo,scaleTo)
    pdb.gimp_image_resize(image,52,52,-1,-1)
    for layer in image.layers:
      pdb.gimp_layer_resize_to_image_size(layer)
    # layer_group = pdb.gimp_layer_group_new(image)
    layer_group=pdb.gimp_item_get_parent(image.layers[0])
    layer=pdb.gimp_file_load_layer(image, file)
    pdb.gimp_image_insert_layer(image,layer,layer_group,1)#(image, layer, parent, position)
    for layer in image.layers:
      pdb.gimp_item_set_visible(layer,True)
    layer = pdb.gimp_image_merge_visible_layers(image, 0)
    pdb.gimp_image_set_active_layer(image, layer)
    drawable = pdb.gimp_image_get_active_layer(image)
    # with open("E:/out.txt",'w') as outTxt:
    #   outTxt.write(outFile)
    pdb.file_dds_save(image, drawable, outFile,outFile,0,0,0,0,0,0,0)