Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Programmatic XCF text layer editing
#5
(02-12-2023, 12:39 AM)Ofnuts Wrote: You don't need to open the UI(*), you can use Gimp+Python in batch mode from a shell (or shell script), but your script still has to start a Gimp process and tell it to run your Python. See this example.

(*) Although another option is to write a plugin that takes a directory as input and process all images in that directory by itself. Called from the Gimp UI, but doesn't require user interaction once started.

Tried several things but I'm getting errors:
I'm on GIMP 2.10.28

GIMP-Warning: The batch interpreter 'python-fu-eval' is not available. Batch mode disabled.

or when modifying the command:

GIMP-Warning: The batch interpreter 'python-fu-eval-image' is not available. Batch mode disabled.

My shell command is:
gimp -idf --batch-interpreter python-fu-eval -b "import sys;sys.path=['/home/Kaitlyn/Desktop']+sys.path;import ChangeGimpTextLayersSample;ChangeGimpTextLayersSample.run('/home/User/Desktop/FieldSheet.xcf')" -b "pdb.gimp_quit(1)"

The script, called ChangeGimpTextLayersSample.py is in the same folder as the XCF fil (i.e right on the Desktop)
And the contents of the script is below: 


Code:
import sys
import os
import traceback
import logging
from gimpfu import *
import gimpcolor
from collections import namedtuple

logging.basicConfig(filename='/home/User/Desktop/gimp_script_log.log', level=logging.DEBUG)

file_path = "/home/User/Desktop/FieldSheet.xcf"

if os.path.exists(file_path):
    logging.debug("Found FieldSheet.xcf")
    image = pdb.gimp_xcf_load(0, file_path, file_path)
    layers = image.layers
    for layer in layers:
        if layer.name == "ChangeMe":
            logging.debug("Found ChangeMe layer")
            pdb.gimp_text_layer_set_text(layer, "Testing Script")
    pdb.gimp_xcf_save(0, image, image.active_layer, "/home/User/Desktop/test.xcf", "test.xcf")
    logging.debug("Finished processing FieldSheet.xcf")
else:
    logging.debug("The file does not exist.")
Reply


Messages In This Thread
RE: Programmatic XCF text layer editing - by Anthony Buff - 02-12-2023, 07:33 AM

Forum Jump: