#!/usr/bin/env python # -*- coding: utf-8 -*- # GIMP plugin to export layer combination possibilities defined by groups # (c) ShadowKyogre 2013 # # History: # 2013-07-03 (v0.0): first published version # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. from gimpfu import * import os from itertools import product def deleteAllLayers(image): for l in image.layers: image.remove_layer(l) def permuteLayers(image, dirname, fnf): #image.undo_group_start() target = pdb.gimp_image_new(image.width, image.height, RGB) target.disable_undo() src_lyrs=[] # get all top lvl layer groups for lyr in filter(lambda x: x.visible, image.layers): #only consider children in the canditates for product if they are visible if hasattr(lyr,"layers"): src_lyrs.append([l for l in lyr.layers if l.visible]) else: src_lyrs.append([lyr]) #Get permutations for the layer groups # for prm in product(*src_lyrs): #place the layers in the mixture into a brand spanking new image for l in reversed(prm): n=pdb.gimp_layer_new_from_drawable(l,target) if l.parent is not None: n.mode=l.parent.mode n.opacity=l.parent.opacity*l.opacity/1E2 target.add_layer(n,0) #process! expanded_fnf=fnf.format(*prm) fullname=os.path.join(dirname,expanded_fnf) if not os.path.exists(os.path.dirname(fullname)): os.makedirs(os.path.dirname(fullname)) result=target.merge_visible_layers(EXPAND_AS_NECESSARY) #or CLIP_TO_IMAGE #gimp.message(expanded_fnf) pdb.gimp_file_save(target, result, fullname, os.path.basename(fullname), run_mode=RUN_NONINTERACTIVE) deleteAllLayers(target) pdb.gimp_image_delete(target) #image.undo_group_end() ### Registrations register( 'permute-layer-groups', 'Permute Layer Groups', 'Save all possible permutations for each layer group combination to files', 'ShadowKyogre', 'ShadowKyogre', '2013', 'Permute Layer Groups', '*', [ (PF_IMAGE, 'image', 'Input image', None), (PF_DIRNAME, 'dirname', 'Output Directory', os.path.expanduser('~')), (PF_STRING, 'fnf', 'Filename format:\n' 'Use {i.name} for the layer name picked out from the ' 'top level group.\n' 'Numbers start at 0 from the topmost layer', "{0.name}/{1.name}.png"), ], [], permuteLayers, menu='/File/Save', ) main()