如何在Python中正确调用GIMP PDB的file_raw_save方法?
问题
使用Python 2.7 + gimpfu开发GIMP 2.8插件时,调用pdb.file_raw_save方法出现段错误及RuntimeError: calling error。尝试调整两个文件名参数(怀疑分别对应路径和文件名)后问题仍存在,且未找到相关文档。
插件代码:
def save_aci(save_img, filename): img = save_img filename = filename.strip() pdb.file_raw_save(img, img.layers[0], filename, filename) register( "python_fu_save_aci", "Exports to ACI file", "Exports image to ACI file, with LODs if they are present", "Author", "Author", "2023", "Save ACI File", "GRAYA", # Currently only support export from Grayscale image (with alpha) to (RG_88) .aci format [ (PF_IMAGE, "save_img", "Image to Save", None), (PF_FILE, "filename", "Filename Fullpath", None), ], [], save_aci, menu="<Image>/File/") main()
运行时输出:
/home/astro/.gimp-2.8/plug-ins/testplugin.py: fatal error: Segmentation fault ^C/usr/lib64/gimp/2.0/plug-ins/script-fu terminated: Interrupt gimp: terminated: Interrupt /home/astro/.gimp-2.8/plug-ins/testplugin.py terminated: Interrupt /home/astro/.gimp-2.8/plug-ins/testplugin.py terminated: Interrupt [astro@cobalt-vm plug-ins]$ gimp Traceback (most recent call last): File "/usr/lib64/gimp/2.0/python/gimpfu.py", line 736, in response dialog.res = run_script(params) File "/usr/lib64/gimp/2.0/python/gimpfu.py", line 361, in run_script return apply(function, params) File "/home/astro/.gimp-2.8/plug-ins/testplugin.py", line 128, in save_aci pdb.file_raw_save(img, img.layers[0], filename, filename) RuntimeError: calling error
解决建议
- 核心问题:用错函数:
pdb.file_raw_save是GIMP用于保存相机RAW格式(如CR2、NEF等)的专用函数,并非用于自定义ACI格式。如果ACI是你需要的特定格式,不要用这个函数,应该直接读取图像像素数据,按照ACI格式的规范手动写入文件。 - 验证函数参数(若坚持使用):打开GIMP的Python-Fu控制台(
Filters->Python-Fu->Console),输入help(pdb.file_raw_save)查看官方参数说明。通常第三个参数是保存路径,第四个是RAW格式内部需要的文件名(多数场景下和路径一致,但部分格式有区分要求),同时要确保图像模式、位深符合该函数的要求。 - 添加调试信息:在调用函数前打印关键参数,确认数据有效性:
检查图像是否为print("Image mode:", img.mode) print("Layer type:", img.layers[0].type) print("Save path:", filename)GRAYA模式、图层数据是否正常、目标路径是否有写入权限。 - 测试图像兼容性:
file_raw_save可能仅支持特定图像模式(如无Alpha的RGB),尝试将图像临时转换为RGB模式后再调用函数测试。 - 调整参数传入:如果第四个参数不需要特殊值,尝试传入空字符串而非重复路径参数,部分pdb函数对重复参数的处理存在异常。
内容的提问来源于stack exchange,提问作者Michael Buerger
相关产品推荐
相关产品推荐

