Search code examples
python-2.7gimpgimpfu

How to properly use file_raw_save via Python (GIMP PDB Procedure)


While writing a GIMP 2.0 plugin via Python and gimpfu, I've run into pdb procedures such as file_raw_save(...). There arguments are laid out in the GIMP Procedure Browser (Help->Procedure Browser). But when calling them I receive very unhelpful output. My code and output is as follows:

Plugin code:

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

Output when running GIMP plugin:

/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

After messing around with the filename arguments (perhaps one expected a path, and the other just a filename), the same output occurs. I was unable to find any documentation on this issue either.

My GIMP version is 2.8 and GIMP is running the script via Python 2.7.

Any suggestions?


Solution

  • Your code is OK and works in Gimp 2.10. I get the same calling error when I run it in my Gimp 2.8. So I assume it's a bug that was fixed later.

    Gimp 2.10 has been around for over 5 years, so why Gimp 2.8?