Hi,
I am trying to do some python gimp scripting but impossible to understand
how to install the gimpfu module on my debian 11 :
Can please someone help me ?
Thanks.
devel@k0:~/.config/GIMP/2.10/plug-ins$ ./ofn-export-layers-combinations.py
Traceback (most recent call last):
File "./ofn-export-layers-combinations.py", line 30, in <module>
from gimpfu import *
ImportError: No module named gimpfu
devel@k0:~/.config/GIMP/2.10/plug-ins$ cat ofn-export-layers-combinations.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# GIMP plugin to create images that are comninations of layers
# (c) Ofnuts 2021
#
# History:
#
# v0.0: 2021-12-xx: First published version
version='0.0'
# 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.
import sys,os,time,traceback
from itertools import product
from gimpfu import *
debug='OFN_DEBUG' in os.environ
def trace(format,*args):
if debug:
print format % args
def combinableLayersVisible(combinableLayers,state):
for g in combinableLayers:
for l in g:
l.visible=state
def exportLayersCombinations(image,directory):
try:
if not image.filename:
imageName='Layers'
else:
imageName,_=os.path.splitext(os.path.basename(image.filename))
# We combine the visible things in the visible first level groups
# list (one per 1st level group) of lists of layers
combinableLayers=[[l for l in g.layers if l.visible] for g in
image.layers if g.visible and isinstance(g,gimp.GroupLayer)]
# Not strictly necessary but makes for cleaner output names
combinableLayers=[l for l in combinableLayers if len(l)>1 ]
# hide all these layers
combinableLayersVisible(combinableLayers,False)
# itertools product(lists...) will generate all combos of one item
in each list
for layers in product(*combinableLayers):
print layers
for l in layers:
l.visible=True
layersPart="-".join([l.name for l in layers])
outputName=filename=os.path.join(directory,imageName+"-"+layersPart+".png")
savedLayer=pdb.gimp_layer_new_from_visible(image,image,"###")
pdb.gimp_file_save(image,savedLayer,outputName,outputName)
gimp.delete(savedLayer)
# export goes here
for l in layers:
l.visible=False
# restore all these layers
combinableLayersVisible(combinableLayers,True)
except Exception as e:
pdb.gimp_message(e.args[0])
print traceback.format_exc()
### Registrations
# Some variables to avoid repeating myself
### Registrations
author='Ofnuts'
year='2021'
exportMenu='<Image>/File/Export/'
exportDesc='Export layer combinations'
whoiam='\n'+os.path.abspath(sys.argv[0])
register(
'ofn-export-layers-combinations',
exportDesc,exportDesc+whoiam,author,author,year,exportDesc+'...',
'*',
[
(PF_IMAGE, 'image', 'Input image', None),
(PF_DIRNAME, 'directory', 'Directory', '.'),
# (PF_STRING, 'namePattern', 'Layer name', '{imageName}-
{name}.png'),
],
[],
exportLayersCombinations,
menu=exportMenu
)
main()