在多个图像上应用合并图层而不丢失图层

发布于 2024-10-28 01:14:56 字数 348 浏览 3 评论 0原文

我的问题: 我想制作很多仅在三个文本层上有所不同的图像。我已经弄清楚如何使用 Python-Fu 控制台更改文本。我的下一步是将此文本更改代码放入循环中并添加 png.file-save-png(...) 来保存图片。为了保存为 PNG,我必须合并所有图层(对于每个图像),这对于 single_layer = pdb.gimp-image-merge-visible-layers(image,0) 来说没有问题。为了从这里继续工作,我需要撤消,以恢复我的旧图层。

我是否需要从脚本在 GIMP 中应用 UNDO 操作?

我找不到有关此功能的任何提示。也许有人知道如何做到这一点,或者有解决方法。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疯狂的代价 2024-11-04 01:14:56

经过一夜的睡眠后,我找到了一个解决方法:

我重新打开循环中每张卡片的基本图像文件,其中所有图层和文本图层保持不变。这使我不需要撤消。

顺便说一句,这是我创建 4 * 13 扑克牌的脚本(来自自己的 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)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文