So, noch mal abschließend, Gimplyworxs hat mir ein Script geschickt das schon sehr gut aussah und mit ein bisschen umstellen auch das gemacht hat was ich wollte.
Ich habe das Skript nun noch ein wenig verändert und nun tut es genau das was ich will:
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# https://stackoverflow.com/questions/5794640/how-to-convert-xcf-to-png-using-gimp-from-the-command-line
# http://gimpchat.com/viewtopic.php?f=9&t=15024
from gimpfu import *
import os
def batch_convert_xcf_to_png(inputFolder, outputFolder, color, randbreite, ebenen_name):
''' Convert the xcf images in a directory to png.
Parameters:
img : image The current image (unused).
layer : layer The layer of the image that is selected (unused).
inputFolder : string The folder of the images that must be modified.
outputFolder : string The folder in which save the modified images.
'''
# Iterate the folder
for file in os.listdir(inputFolder):
try:
# Build the full file paths.
inputPath = inputFolder + "/" + file
new_name = file.rsplit(".",1)[0] + ".png"
outputPath = outputFolder + "/" + new_name
# Open the file if is a XCF image.
image = None
if(file.lower().endswith(('.xcf'))):
image = pdb.gimp_xcf_load(1,inputPath, inputPath)
# ab hier
layer = pdb.gimp_image_get_layer_by_name(image, ebenen_name)
parent = pdb.gimp_item_get_parent(layer)
# Auswahl aus Alphakanal:
pdb.gimp_image_select_item(image, CHANNEL_OP_ADD, layer)
# um randbreite größer:
pdb.gimp_selection_grow(image, randbreite)
# neue Ebene erstellen
outline_layer = pdb.gimp_layer_new(image, image.width, image.height, RGBA_IMAGE, "outline", 100, LAYER_MODE_NORMAL)
# Ebene einfügen
pdb.gimp_image_insert_layer(image, outline_layer, parent, -1)
# Ebene absenken unter den Text
pdb.gimp_image_lower_item(image, outline_layer)
# Vordergrundfarbe setzen:
pdb.gimp_context_set_foreground(color)
# Outline Ebene füllen
# pdb.gimp_drawable_fill(outline_layer, FILL_FOREGROUND)
pdb.gimp_edit_bucket_fill(outline_layer, BUCKET_FILL_FG, LAYER_MODE_NORMAL, 100, 0, FALSE, 0, 0)
# Auswahl wieder entfernen
pdb.gimp_selection_none(image)
# bis hier
# Verify if the file is an image.
if(image != None):
#layer = pdb.gimp_image_merge_visible_layers(image, gimpfu.CLIP_TO_IMAGE)
layer = pdb.gimp_image_merge_visible_layers(image, 1)
# Save the image.
# pdb.file_png_save(image, drawable, filename, raw_filename, interlace, compression, bkgd, gama, offs, phys, time)
pdb.file_png_save(image, layer, outputPath, outputPath, 0, 9, 0, 0, 0, 0, 0)
except Exception as err:
gimp.message("Unexpected error: " + str(err))
'''
img = pdb.gimp_file_load(filename, filename)
new_name = filename.rsplit(".",1)[0] + ".png"
layer = pdb.gimp_image_merge_visible_layers(img, gimpfu.CLIP_TO_IMAGE)
pdb.gimp_file_save(img, layer, new_name, new_name)
pdb.gimp_image_delete(img)
'''
register(
"batch_convert_xcf_to_png",
"convert chris",
"convert ",
"Chris O'Halloran",
"Chris O'Halloran",
"2014",
"Batch batch convert xcf to png",
"", # start with no image
[
(PF_DIRNAME, "inputFolder", "Input directory", ""),
(PF_DIRNAME, "outputFolder", "Output directory", ""),
(PF_COLOR, "color", "Randfarbe", "#000000"),
(PF_SPINNER, "randbreite", "Randbreite", 5, (1, 10, 1)), # Default,(Minimun,Maximum, Schrittweite)
(PF_STRING, "ebenen_name", "Name zu Umrandenden Ebene", "Product Text"),
],
[],
batch_convert_xcf_to_png, menu="<Image>/Test")
main()
Dieses Skript kann man über gimp ausführen, man gibt ein quell verzeichnis an, ein ausgangs verzeichnis. Rein gehen xcf files und raus kommen pngs.
Randfarbe auswähen womit dann eine schriftebene umrandet wird, ebenso breite und den namen der ebene die umrandet werden soll.
Dann anschmeißen und alle xcf's werden so behandelt und ausgegeben.