The best thing about ThorSummoner's answer is that it called attention to the OpenRaster export plugin, which as it turns out lives in the file file-openraster.py
in the GIMP installation.
By reading its code (and with some assistance from the built-in procedure browser), I was able to determine that the layers of a GIMP XCF can be saved to individual PNGs by going to Filters > Python-fu > Console in the interface, and entering the following into the built-in Python interpreter:
import os
# If you have multiple images open, you may need to adjust
img = gimp.image_list()[0]
savefn = gimp.pdb['file-png-save-defaults']
outpath = "/home/$USER/Pictures" # (or r"C:\Users\$USER\Pictures", etc)
for lay in img.layers:
# Even if your layer names contain spaces, not a problem
outname = lay.name + ".png"
savefn(img, lay, os.path.join(outpath, outname), outname)
# type an extra newline to exit the indented block
You'll see the progress meter in the image window's status bar start whipping through all of your layers, writing each one to a PNG file of the same name, in whatever directory you specified as outpath
. (Which must already exist, otherwise add an os.makedirs(outpath, exist_ok=True)
before the loop.)
If any of your layer names are the same, that is a problem, because this will happily overwrite any previously-written files. Caveat GIMPtor.
Edit: If you do have same-named layers, you could easily ignore the names and instead write out the layers in numbered files. Just replace the final loop above with something like:
for n, lay in enumerate(img.layers):
outname = f"Layer {n:03}.png"
savefn(img, lay, os.path.join(outpath, outname), outname)
That'll write the layers into PNG files named "Layer 000.png" through "Layer 999.png" (or however many layers are present, if fewer than 1000).
If the Gimp's version of Python doesn't support f-strings (Python 3.6+), this is exactly equivalent:
outname = "Layer {0:03}.png".format(n)