1
votes

My problem: I want to make a lot of images that differ only in three text layers. I have already figured out, how to make the text changes with the Python-Fu Console. My next step is to put this text change code into a loop and add a png.file-save-png(...) to save the picture. In order to save as a PNG I have to merge all my layers (for each image), which is no problem with single_layer = pdb.gimp-image-merge-visible-layers(image,0). In order to keep working from here, I would need to to an undo, to get my old layers back.

Do I need to apply an UNDO Operation in GIMP from a script?

I couldn't find any hint on this feature. Maybe anyone knows how to do this, or has a workaround.

1
I'd recommend renaming and editing this question, or your answer should be downvoted - it has nothing to do with undo - jmetz

1 Answers

3
votes

After a night of sleep, I figured out a workaround:

I reopened the base image file for each card in the loop, where all layers and text layers stayed intact. That prevented me from needing the undo.

By the way, here is my script for creating 4 * 13 playing cards (from ones own base_card.xcf):

basefile = "/home/[...]/base_card.xcf"
basesave = "/home/[...]/"

color_blue      = [ (32.0 /255.0, 74.0/255.0,135.0/255.0,1.0),
                    (52.0 /255.0,101.0/255.0,164.0/255.0,1.0)]

color_red       = [ (164.0/255.0,  0.0/255.0,  0.0/255.0,1.0),
                    (204.0/255.0,  0.0/255.0,  0.0/255.0,1.0)]

color_yellow    = [ (196.0/255.0,160.0/255.0,  0.0/255.0,1.0),
                    (237.0/255.0,212.0/255.0,  0.0/255.0,1.0)]

color_green     = [ ( 78.0/255.0,154.0/255.0,  6.0/255.0,1.0),
                    (115.0/255.0,210.0/255.0, 22.0/255.0,1.0)]   

def createCard(color_list, color_name, number):
    pdb.gimp_context_set_foreground(color_list[1])
    image = pdb.gimp_file_load(basefile, basefile)
    textlayers = image.layers[0:3]
    for layer in textlayers:
        pdb.gimp_text_layer_set_text(layer, number)
        pdb.gimp_text_layer_set_color(layer, color_list[0])
    layer = image.layers[3]
    pdb.gimp_edit_bucket_fill(layer, 0, 0, 100, 0, 0, 30, 30)
    layer = pdb.gimp_image_merge_visible_layers(image, 0)
    savename = "%s%s_%s.png" % (basesave, color_name, number)
    pdb.file_png_save(image, layer, savename, savename, 0, 0, 0, 0, 0, 0, 0)
    image = None

for c in range(1,14):
    createCard(color_blue, "BLUE", c)
for c in range(1,14):
    createCard(color_yellow, "YELLOW", c)
for c in range(1,14):
    createCard(color_red, "RED", c)
for c in range(1,14):
    createCard(color_green, "GREEN", c)