如何一次保存多个图层修改
How to save multiple layer modifications in one save
我有一个 python 脚本可以在现有 GIMP 文件中查找和更新多个文本层。我想将整个文件保存为副本。然而,我似乎可以找到使用 pdb.gimp_xcf_save 记录的唯一方法需要我传入一个可绘制对象(我正在使用当前文本层)以将文件另存为 xcf。因此,当我循环遍历它们时,我将对每一层重复此调用。这看起来很浪费,当然必须有一种方法可以解决这个问题,只用一种方法来做,但我找不到它。
def dynamic_text_replace_plugin(timg, tdrawable, pathToXcf, textToReplace, saveAsJpg):
texts = textToReplace.split('~')
myImage = pdb.gimp_xcf_load(1, pathToXcf, pathToXcf)
textCount = 0
for newText in texts:
textCount = textCount + 1
textLabel = "TEXT" + str(textCount)
myLayer = pdb.gimp_image_get_layer_by_name(myImage, textLabel)
sourceText = pdb.gimp_text_layer_get_text(myLayer)
textToReplace = sourceText.replace(textLabel, newText)
pdb.gimp_text_layer_set_text(myLayer, textToReplace)
# Not sure if I can do this once or if it has to be for every layer?
saveAsPath = pathToXcf.replace(".xcf", "_replaced.xcf")
pdb.gimp_xcf_save(1, myImage, myLayer, saveAsPath, saveAsPath)
if (saveAsJpg):
pathToJpg = pathToXcf.replace(".xcf", ".jpg")
myImage.flatten()
pdb.gimp_file_save(myImage, myImage.layers[0], pathToJpg, '?')
# Clean up memory
pdb.gimp_image_delete(myImage)
据我所知,当您保存为 XCF 等多层格式时,"drawable" 参数将被忽略。所以给它任何图像层或 None
并只保存一次:
pdb.gimp_xcf_save(0, image, None,'/tmp/foo.xcf','/tmp/foo.xcf')
我有一个 python 脚本可以在现有 GIMP 文件中查找和更新多个文本层。我想将整个文件保存为副本。然而,我似乎可以找到使用 pdb.gimp_xcf_save 记录的唯一方法需要我传入一个可绘制对象(我正在使用当前文本层)以将文件另存为 xcf。因此,当我循环遍历它们时,我将对每一层重复此调用。这看起来很浪费,当然必须有一种方法可以解决这个问题,只用一种方法来做,但我找不到它。
def dynamic_text_replace_plugin(timg, tdrawable, pathToXcf, textToReplace, saveAsJpg):
texts = textToReplace.split('~')
myImage = pdb.gimp_xcf_load(1, pathToXcf, pathToXcf)
textCount = 0
for newText in texts:
textCount = textCount + 1
textLabel = "TEXT" + str(textCount)
myLayer = pdb.gimp_image_get_layer_by_name(myImage, textLabel)
sourceText = pdb.gimp_text_layer_get_text(myLayer)
textToReplace = sourceText.replace(textLabel, newText)
pdb.gimp_text_layer_set_text(myLayer, textToReplace)
# Not sure if I can do this once or if it has to be for every layer?
saveAsPath = pathToXcf.replace(".xcf", "_replaced.xcf")
pdb.gimp_xcf_save(1, myImage, myLayer, saveAsPath, saveAsPath)
if (saveAsJpg):
pathToJpg = pathToXcf.replace(".xcf", ".jpg")
myImage.flatten()
pdb.gimp_file_save(myImage, myImage.layers[0], pathToJpg, '?')
# Clean up memory
pdb.gimp_image_delete(myImage)
据我所知,当您保存为 XCF 等多层格式时,"drawable" 参数将被忽略。所以给它任何图像层或 None
并只保存一次:
pdb.gimp_xcf_save(0, image, None,'/tmp/foo.xcf','/tmp/foo.xcf')