Full Version: Python Fu: Creating batch path loading and saving plugin.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, this is my first post and I hope it’s correctly written.

My ability to write scripts in Python Fu is very restricted, I have no other knowledge of “general” programing. I did adjust a .py plugin so that my workflow in GIMP 2.8.22 under windows 10 is a bit faster. It’s an automated version of “color to alpha”, name and function is “black to alpha”.

I would like to create a Plugin in Python Fu with interface: It should have PF_DIRNAME for the opening path, and one for the saving path.

Opening path should load all (.tga) files in the interface directory path folder and its subfolders. For each subfolder and its (.tga) files it needs to make .xcf and save this based on the name of the folder and then the subfolder in a selected saving path.

Example: folder name “Gimp” Subfolder name “01”= “Gimp01.xcf”, 
“Gimp01.xcf”, “Gimp02.xcf”, etc...

“Gimp01.xcf” needs to contain the (.tga) files from the subfolder and loads the lowest file number in the highest in layer.

Example: “image0000” and “image 0525” are in subfolder. “image0000” needs to be above “image0525” in the “Gimp01.xcf”

For each image per .xcf it needs to run “black to alpha”.

I hope this is possible with Python-Fu. And if I could get some guidance.

Yes, it is doable. Steep learning curve if you need to learn both Python and Gimp scripting. Some hints:
  • Use os.walk(topdir) to list the contents of the top directories. This produces sperat lists of directories and files
  • All the API documentation is available via Filters>Python-fu>Console>Browse.... It is dynamically generated, you'll even see your black-to-alpha plugin there.
  • The Python-specific bit of the API (using Python ibjects instead of the PDB calls) is documented here:
  • Load the files with layer=pdb.gimp_file_load_layer(image, filename). Once loaded you have to explicitly add the layer to the image (image.add_layer(layer,pos), pos=0 for the top of the stack, pos=len(image.layers) for the bottom).
  • You can make a special case and load the first file with image=pdb.gimp_file_load(filename,filename) to create the image.
  • Try to get at least the file walk working by using Python outside of Gimp (you can run the python executable that comes with Gimp in a terminal/console, it is much easier to debug that way, but this is only possible for code that doesn't interact with Gimp).
  • To debug under Gimp, several hints there:
  • As long as you don't change the registration data, you can modify the script file and execute the new version without needing to restart Gimp.
Good luck.
Thanks for the advice, i am still a long way from creating my plugin, I did find your “Flatten visible layers group…” plugin and it’s saving me a lot of work.