gimpgimpfu

Closing a GIMP image from Python script/plugin


I have just written my first GIMP plug-in, and it generates a potentially large number of open images (iterating through loop, creating & saving images each time). When I call gimp.image_list() from the Python console I see all of them still open, and the memory usage of GIMP is higher than I suspect it should be.

I suppose I could display the windows to the user, but then they'd have to click close on each one. This seems even worse to me than just having to close and relaunch GIMP after running the script.

I tried calling gimp.quit(), but that seems to just make the script stop. I've been sifting through the API documentation and the built-in "Procedure browser" tool but have not been able to find a way to close these. It seems like it should be simple. How can I close an Image object so that GIMP unloads it from memory & takes it out of gimp.image_list()?


Solution

  • If you want to close an image that isn't displayed, this seems to be the way that it's intended to be done --> gimp.pdb.gimp_image_delete(img)

    Otherwise, if the image is being displayed by d then you can do something like this --> gimp.pdb.gimp_display_delete(d)

    Refer to: