Calling gimp_image_convert_indexed with a custom palette, palette cant be found

294 Views Asked by At

I am making a script to limit any image into 3 colors (to be used in a program to display to an e-ink display). I want to do this using GIMP's gimp_image_convert_indexed function bc Wand and PIP's .quantize don't work how I want them to and don't look as good. This is on a headless raspi zero.

When I call the script using gimp -idf --batch-interpreter python-fu-eval -b 'import sys;sys.path=["."]+sys.path;import colorindex;colorindex.python_colorindex("gimptemp.jpg")' -b 'pdb.gimp_quit(1)' it gives me the 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
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

The custom palette is in GIMP's palette folder (it's even recognized when I open palettes through the UI) and for safe measure I put a copy of the palette in the directory the script is running from. I tried setting the name of the file and the name of the palette to "eink" rather than "E-Ink" and it had the same error. Same thing happened when I specified the filepath ("/home/pi/.config/GIMP/2.10/palettes/E-Ink.gpl") instead of "E-Ink".

Here is colorindex.py (the gimp script)

import os
from gimpfu import *
def python_colorindex(file):
    os.system("echo gimp")
    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")
    os.system("echo processed image")
    pdb.gimp_file_save(image, drawable, file, file)
    pdb.gimp_image_delete(image)
    print("Exit")

Here is showing the error and the paths to the palette

Here is showing gimp recognizing the palette (running on the same machine but GUI through Xming)

1

There are 1 best solutions below

1
On BEST ANSWER

On your command line you've specified the -d option that tells GIMP not to load any data: i.e. "Do not load brushes, gradients, palettes, patterns, ..." so your script won't have your palette loaded.