GIMP script can find custom palette when run in terminal but cant when inside a program

153 Views Asked by At

I want to execute gimp -if --batch-interpreter python-fu-eval -b 'import sys;sys.path=["."]+sys.path;import colorindex;colorindex.python_colorindex("gimptemp.jpg")' -b 'pdb.gimp_quit(1)' (which works fine when run in the terminal) from inside a script like this colorindex = subprocess.run(["/usr/bin/gimp", "-if", "--batch-interpreter", "python-fu-eval", "-b", "import sys;sys.path=['.']+sys.path;import colorindex;colorindex.python_colorindex('gimptemp.jpg')", "-b", "pdb.gimp_quit(1)"]) (which errors bc a gimp function cant find a needed palette)

Error:

GIMP-Error: Calling error for procedure 'gimp-image-convert-indexed':
Palette 'E-Ink' not found

Traceback (most recent call last):
  File "/usr/lib/gimp/2.0/python/gimpfu.py", line 827, in _run
    return apply(func, params[1:])
  File "/usr/lib/gimp/2.0/plug-ins/python-eval/python-eval.py", line 25, in code_eval
    exec code in globals()
  File "<string>", line 1, in <module>
  File "./colorindex.py", line 7, in python_colorindex
    pdb.gimp_image_convert_indexed(image, 1, 4, 3, FALSE, FALSE, "E-Ink")
RuntimeError: Palette 'E-Ink' not found
batch command experienced an execution error
/usr/bin/gimp: GEGL-WARNING: (gegl-tile-handler-cache.c:977):gegl_tile_cache_destroy: runtime check failed: (g_queue_is_empty (&cache_queue))
EEEEeEeek! 2 GeglBuffers leaked

I got the same issue in terminal when I accidentally left in the -d flag blocking brushes and things from loading, but obviously I took that out so idk what could be blocking the palette from loading this time, especially when it works in terminal. Using subprocess.Popen instead didn't change the error. The custom palette doesnt show up in the palette tray gui when I open gimp through the script, but it does show up in the gui when ran through terminal

Here's colorindex.py

import os
from gimpfu import *
def python_colorindex(file):
    image = pdb.gimp_file_load(file, file, run_mode=RUN_NONINTERACTIVE)
    drawable = pdb.gimp_image_get_active_layer(image)
    pdb.gimp_image_convert_indexed(image, 1, 4, 3, FALSE, FALSE, "E-Ink")
    pdb.file_png_save(image, drawable, file, file, 0, 0, 0, 0, 0, 0, 0)
    pdb.gimp_image_delete(image)
    print("Exit")
1

There are 1 best solutions below

1
On BEST ANSWER

I can't replicate this as I'm a Windows user, but I assume that your E-Ink.gpl palette is saved in your personal palette directory, maybe running gimp as a subprocess from python isn't loading your personal files.

You might try forcing gimp to use your personal setup by using the --gimprc=filename option to point to your personal gimprc file.