问题描述
我正在制作一个脚本,将任何图像限制为 3 种颜色(用于在程序中显示到电子墨水显示器)。我想使用 GIMP 的 gimp_image_convert_indexed 函数 bc Wand 和 PIP 的 .quantize 不按照我希望的方式工作,看起来也不那么好。这是在无头 raspi 零上。
当我使用 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,"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/palettes/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,"e-ink")
os.system("echo processed image")
pdb.gimp_file_save(image,drawable,file)
pdb.gimp_image_delete(image)
print("Exit")
这里是showing the error and the paths to the palette
这里是 showing gimp recognizing the palette(在同一台机器上运行,但通过 Xming 使用 GUI)
解决方法
在您的命令行中,您已指定 -d 选项告诉 GIMP 不加载任何数据:即“不加载画笔、渐变、调色板、图案,...”,因此您的脚本将没有您的调色板已加载。