Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Processing XCF files in batch
#4
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:
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)
The gimp.py file then contains the following code:
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?
Reply


Messages In This Thread
Processing XCF files in batch - by Mate de Vita - 12-01-2022, 03:38 PM
RE: Processing XCF files in batch - by Ofnuts - 12-02-2022, 05:48 PM
RE: Processing XCF files in batch - by Mate de Vita - 12-09-2022, 03:43 PM
RE: Processing XCF files in batch - by Ofnuts - 12-10-2022, 07:39 AM
RE: Processing XCF files in batch - by rich2005 - 12-09-2022, 04:53 PM
RE: Processing XCF files in batch - by rich2005 - 12-09-2022, 09:02 PM
RE: Processing XCF files in batch - by Ofnuts - 12-11-2022, 04:55 PM
RE: Processing XCF files in batch - by Ofnuts - 12-16-2022, 08:18 AM
RE: Processing XCF files in batch - by Ofnuts - 12-16-2022, 12:54 PM

Forum Jump: