I've a huge list of directories containing for each 2 images : 1 jpg file and 1 png file; I want to create from an external script all the .xcf associated with the jpg as first layer. After trying with python I've been drowning in scheme explanations and other linked subjects ... Can someone help me to make such command and understand it ?
Asked
Active
Viewed 1,662 times
1 Answers
1
Typically, something like this, for each pair of images:
image=pdb.gimp_file_load(jpgImage,jpgImage)
layer=pdb.gimp_file_load_layer(image,pngImage)
image.add_layer(layer,0)
pdb.gimp_xcf_save(0,image,layer,outputImage,outputImage)
The ofn-coalesce-images script does something very similar (stacks all images found in a directory)...
To run such a thing in headless Gimp, consider a .py that will run staring from some specified root directory:
def run(directory):
# Iterates subdirs and creates images
This .py doesn't need to be formally a python plugin (no need to register() anything). Then you can launch it using:
Unix-ish:
gimp -idf --batch-interpreter python-fu-eval -b 'import sys; sys.path=["."]+sys.path;import batch;batch.run("/some/path")' -b 'pdb.gimp_quit(1)'
Windows:
gimp -idf --batch-interpreter python-fu-eval -b "import sys;sys.path=['.']+sys.path;import batch;batch.run('/some/path')" -b "pdb.gimp_quit(1)"
(this is a bit convoluted because Linux and Windows have somewhat opposite ways to deal with quotes and double quotes in the command line).

xenoid
- 8,396
- 3
- 23
- 49
-
is this coalesce-images still supposed to work on GIMP2.10? I've put it in my scripts folder, made it executable, restarted GIMP but couldn't find it anywhere in the interface. – ChameleonScales Jun 18 '20 at 08:54
-
@Gamnamno Python scripts are technically "plugins" and should go in the "plugins" folder. – xenoid Jun 18 '20 at 09:22
-
I went in "Edit > Preferences > Folders > Plug-ins", copied the path, put the py file there, restarted GIMP, went in "Help > Plug-in Browser" and searched for "coalesce" or "ofn", there's no result. I've tried with and without the file being executable. – ChameleonScales Jun 18 '20 at 09:33
-
Still works for me in 2.10 on Ubuntu 19.10. Start Gimp in a terminal and watch for error messages. Also check if the plugin is referenced in the pluginrc file in your Gimp user profile (likely not, but just to make sure). You can also edit the file and put a big fat `print '*********************'` at the top to see if it is at least executed hen Gimp starts. – xenoid Jun 18 '20 at 10:52
-
Silly me, I didn't have gimp-python installed. It works now. Thanks for your help – ChameleonScales Jun 18 '20 at 12:21