12-09-2022, 03:43 PM
(This post was last modified: 12-09-2022, 04:04 PM by Mate de Vita.)
So this is how far I've gotten using the GIMP docs and a ton of googling:
I find my files in a python script and then use the following code to call a separate GIMP script on each of the files:
The gimp.py file then contains the following code:
However this results in a bunch of batch command experienced an execution error error messages, which I don't know how to debug, since printing doesn't seem to work from the gimp script so I can't even tell where the error is happening.
What would be the correct way to fill the layers with the desired colours?
I find my files in a python script and then use the following code to call a separate GIMP script on each of the files:
Code:
for f in found_files:
scriptpath = r'path/to/script'
scriptname = 'gimp.py'
pycode = f'import sys; sys.path.insert(0, "{scriptpath}"); import {scriptname}; {scriptname}.run({f})'
subprocess.run(f'gimp -idf --batch-interpreter python-fu-eval -b \'{pycode}\' -b \'pdb.gimp_quit(1)\'', shell=True, check=True)
Code:
from gimpfu import *
import gimpcolor
def run(f):
xcf = pdb.gimp_xcf_load(0, f, f)
for layer in xcf.layers:
layer.opacity = 100.
if layer.name == 'Currently Green':
pdb.gimp_context_set_foreground(gimpcolor.RGB(255, 0, 0))
layer.fill(FOREGROUND_FILL)
elif layer.name == 'Currently Red':
pdb.gimp_context_set_foreground(gimpcolor.RGB(0, 255, 0))
layer.fill(FOREGROUND_FILL)
pdb.gimp_xcf_save(0, xcf, None, '/path/to/save/to.xcf', '/path/to/save/to.xcf')
xcf.merge_visible_layers(NORMAL_MODE)
pdb.file_png_save(xcf, xcf.layers[0], '/export/path.png', '/export/path.png', 0, 9, 1, 0, 0, 1, 1)
However this results in a bunch of batch command experienced an execution error error messages, which I don't know how to debug, since printing doesn't seem to work from the gimp script so I can't even tell where the error is happening.
What would be the correct way to fill the layers with the desired colours?