Skip to content

Instantly share code, notes, and snippets.

@ajshort
Created November 26, 2010 03:51
Show Gist options
  • Save ajshort/716261 to your computer and use it in GitHub Desktop.
Save ajshort/716261 to your computer and use it in GitHub Desktop.
GIMP Python script to export each layer as a separate image.
#!/usr/bin/env python
#
# A GIMP plugin to save each layer in an image as a separate file
from gimpfu import *
import os
def export_layers(img, drw, path, name):
img = img.duplicate()
for layer in img.layers:
layer.visible = False
for idx, layer in enumerate(img.layers):
layer.visible = True
filename = name % [ idx, layer.name ]
fullpath = os.path.join(path, filename)
layer_img = img.duplicate()
layer_img.flatten()
pdb.gimp_file_save(layer_img, drw, fullpath, filename)
img.remove_layer(layer)
register(
"python-fu-export-layers",
"Export Layers",
"Exports each layer as a separate file",
"Andrew Short",
"",
"",
"E_xport Layers...",
"*",
[
(PF_IMAGE, "img", "Input image", None),
(PF_DRAWABLE, "drw", "Input drawable", None),
(PF_DIRNAME, "path", "Output directory", os.getcwd()),
(PF_STRING, "name", "Output name", "layer_%d.jpg")
],
[],
export_layers,
menu="<Image>/File/"
)
main()
@Finni123
Copy link

Since this is the top entry when searching "GIMP export all layers", I will note this here for everyone who wants to use this script aswell:

  • In line 17, you have to use parentheses (...) instead of brackets [...]
  • In line 39, you should change "layer_%d.jpg" to "layer_%d_%s.jpg" (or something similar, you just need the %d and the %s.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment