Last active
August 29, 2015 14:14
-
-
Save c6p/f46e17c90e429d9698b6 to your computer and use it in GitHub Desktop.
Gimp PythonFu: Extract Visible Layers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from gimpfu import * | |
import os | |
def extract_layer(img, layer, path): | |
if pdb.gimp_item_get_visible(layer): | |
name = path + '/' + layer.name | |
if pdb.gimp_item_is_group(layer): | |
if not os.path.exists(name): | |
os.mkdir(name) | |
for l in layer.layers: | |
extract_layer(img, l, name) | |
else: | |
tmp_layer = layer.copy() | |
name_png = name + '.png' | |
pdb.gimp_image_insert_layer(img, tmp_layer, None, -1) | |
pdb.plug_in_autocrop_layer(img, tmp_layer) | |
pdb.file_png_save_defaults(img, tmp_layer, name_png, os.path.basename(name_png)) | |
pdb.gimp_image_remove_layer(img, tmp_layer) | |
def extract_layers(img, drawable, path): | |
pdb.gimp_image_undo_freeze(img) | |
for layer in img.layers: | |
extract_layer(img, layer, path) | |
pdb.gimp_image_undo_thaw(img) | |
# Register with The Gimp | |
register( | |
"extract_layers", | |
"Extract Visible Layers", | |
"Extract Visible Layers", | |
"Can Altiparmak", | |
"(c) 2015, Can Altiparmak", | |
"2015-01-24", | |
"<Image>/Filters/Extract Visible Layers", | |
"*", | |
[ | |
(PF_DIRNAME, "path", "DIRNAME:", 0) | |
], | |
[], | |
extract_layers); | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment