I'm trying to batch process images in GIMP 2.10 using a Python-Fu script. The script should apply the following transformations to each image in a folder:
- color to alpha with RGB value (246, 246, 246)
- transparency threshold of 0.035
- opacity threshold of 1.000 The processed images should be saved to a different folder.
I'm using the following code:
#!/usr/bin/env python
from gimpfu import *
import os
def batch_process_color_to_alpha_opacity_threshold(input_folder, output_folder):
"""
Batch process images in input_folder and save them in output_folder after applying color to alpha and opacity threshold
"""
# Make sure output folder exists
if not os.path.exists(output_folder):
os.makedirs(output_folder)
# Loop over files in input folder
for filename in os.listdir(input_folder):
# Open the image
input_path = os.path.join(input_folder, filename)
image = pdb.gimp_file_load(input_path, input_path)
# Get the layer
layer = pdb.gimp_image_get_active_layer(image)
# Apply color to alpha
pdb.gimp_layer_add_alpha(layer)
pdb.gimp_color_to_alpha(layer, (246,246,246))
# Apply transparency threshold
pdb.plug_in_transparency_threshold(image, layer, 0.035, 0.0, 1.0)
# Apply opacity threshold
pdb.plug_in_opacity_threshold(image, layer, 1.0, 0.0, 1.0)
# Save the processed image
output_path = os.path.join(output_folder, filename)
pdb.gimp_file_save(image, layer, output_path, output_path)
# Close the image
pdb.gimp_image_delete(image)
pdb.gimp_quit(0)
# Register the script with GIMP
register(
"python_fu_batch_process_color_to_alpha_opacity_threshold",
"Batch process images with color to alpha and opacity threshold",
"Batch process images in a folder with color to alpha and opacity threshold, and save them in a different folder.",
"Author Name",
"Author Name",
"2023",
"<Toolbox>/Filters/Batch Process Color to Alpha and Opacity Threshold",
"*",
[
(PF_DIRNAME, "input_folder", "Input folder", "C:/folder"),
(PF_DIRNAME, "output_folder", "Output folder", "C:/folder2"),
],
[],
batch_process_color_to_alpha_opacity_threshold,
)
# Start the script
main()
After I put the python file containing the code above in GIMP plug-ins, and apply the script in the python console in GIMP, I automatically get this line in the console : pdb.python_fu_batch_process_color_to_alpha_opacity_threshold(input_folder, output_folder))
But this error occurs:
Traceback (most recent call last):
File "<input>", line 1, in <module>
RuntimeError: execution error
And at the same time, a pop-up appears:
Calling error for procedure 'gimp-procedural-db-proc-info':
Procedure 'gimp-color-to-alpha' not found
I already checked that the GIMP Python plug-ins directory is set up correctly. I also ran a different GIMP Python plug-in to see if the issue is specific to my script, and it worked fine.
Can someone please help me figure out what's wrong with my code?