Created
October 13, 2017 15:29
-
-
Save RichardHladik/768cea3a6de366f7561076b63f5e6610 to your computer and use it in GitHub Desktop.
Batch layer export for GIMP
This file contains hidden or 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
| # -*- coding: utf8 -*- | |
| #!/usr/bin/env python2 | |
| """Exports every layer into a separate PNG, adds the same background to each | |
| layer. Useful e.g. for creating flashcards with many things highlighted in one | |
| image. | |
| Installation: put into ~/.gimp-2.8/plug-ins (or similar).""" | |
| from gimpfu import * | |
| import gimp as g | |
| def batch_save(img, layer, dir): | |
| for layer in img.layers: | |
| if (layer.name == "Background"): | |
| background = layer | |
| layer.visible = 2 | |
| newimage = g.Image(layer.width, layer.height, RGB) | |
| for layer in img.layers: | |
| if layer.name == "Background": | |
| continue | |
| fn = dir + "/" + layer.name + ".png" | |
| ll = pdb.gimp_layer_new_from_drawable(layer, newimage) | |
| newimage.add_layer(pdb.gimp_layer_new_from_drawable(background, newimage)) | |
| newimage.add_layer(ll) | |
| flattened = i.flatten() | |
| pdb.file_png_save(newimage, flattened, fn, fn, False, 9, True, True, True, True, True) | |
| i.remove_layer(flattened) | |
| register( | |
| "python_fu_batch_save", | |
| "Export every layer separately as a png with background included", | |
| "Export every layer separately as a png with background included", | |
| "Richard Hladík", | |
| "Richard Hladík", "2017", "<Image>/Filters/Batch/Batch save", | |
| "*", [(PF_STRING, "dir", "Destination directory", "")], | |
| [], | |
| batch_save) | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment