调用gimp_image_convert_使用自定义调色板编制索引,找不到调色板

2024-05-20 20:46:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在制作一个脚本,将任何图像限制为3种颜色(在程序中用于显示电子墨水显示器)。我想用GIMP的GIMP_image_convert_索引函数bc Wand和PIP来实现这一点。这是在一个无头的拉斯皮零点上

当我使用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)'调用脚本时,会出现以下错误:

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

自定义调色板位于GIMP的调色板文件夹中(当我通过UI打开调色板时甚至可以识别),为了安全起见,我将调色板的副本放在脚本运行的目录中。我尝试将文件名和调色板名设置为“eink”而不是“E-Ink”,但它也出现了相同的错误。当我指定文件路径(“/home/pi/.config/GIMP/2.10/paletes/E-Ink.gpl”)而不是“E-Ink”时,也发生了同样的事情

下面是colorindex.py(gimp脚本)

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")

这里是showing the error and the paths to the palette

下面是showing gimp recognizing the palette(在同一台机器上运行,但通过Xming实现GUI)


Tags: inpyimageimport脚本convertevalpdb