To do all of this:
- Copy this GIMP python-fu script:
#!/usr/bin/env python
from gimpfu import *
def scale_level_save(ignored1, ignored2, scale_x, scale_y, black, white):
# Get the list of all opened images
images = gimp.image_list()
image_number = len(images)
# Loop through each image
for i in range(image_number):
current_image = images[i]
current_drawable = current_image.active_layer
pdb.gimp_progress_update((i * 1.0) / image_number)
pdb.gimp_progress_set_text("Processing image #" + str(i + 1) + "/" + str(image_number) + "...")
# Save the image type
mode = current_image.base_type
if mode != RGB:
pdb.gimp_convert_rgb(current_image)
# 1. Scale the image using Sinc (Lanczos3) interpolation
# Get the original dimensions of the image
orig_width, orig_height = current_image.width, current_image.height
# Calculate width and height from the scaling factors
new_width, new_height = current_image.width * scale_x, current_image.height * scale_y
# Scale the image using the Sinc (Lanczos3) interpolation method
pdb.gimp_image_scale_full(current_image, new_width, new_height, INTERPOLATION_LANCZOS)
# Scale the drawable (layer) to match the image dimensions
pdb.gimp_layer_scale(current_drawable, new_width, new_height, True)
# Resize the image canvas if the new dimensions are larger than the original
if scale_x > 1 or scale_y > 1:
pdb.gimp_image_resize(current_image, new_width, new_height, 0, 0)
# 2. Change the input levels to a certain value
pdb.gimp_levels(current_image.active_layer, 0, black, white, 1, 0, 255)
# Restore the image type
if mode == INDEXED:
pdb.gimp_image_convert_indexed(current_image, NO_DITHER, MAKE_PALETTE, 256, FALSE, FALSE, '')
elif mode == GRAY:
pdb.gimp_image_convert_grayscale(current_image)
# 3. Save the file
filename = pdb.gimp_image_get_filename(current_image)
pdb.gimp_file_save(current_image, current_image.active_layer, filename, '?')
# Refresh the image to see the changes
pdb.gimp_displays_flush()
# Define the parameters for the script
register(
"python_fu_scale_level_save",
"Scale image using Sinc (Lanczos3) interpolation, level and save",
"Scale the image with the Sinc (Lanczos3) interpolation method",
"Fabrice TIERCELIN",
"Fabrice TIERCELIN",
"2023",
"<Image>/Filters/Scale Level and Save",
"*",
[
(PF_FLOAT, "scale_x", "Scale X:", 2),
(PF_FLOAT, "scale_y", "Scale Y:", 2),
(PF_SPINNER, "black", "Black level (0-255)", 0, (0, 255, 1)),
(PF_SPINNER, "white", "White level (0-255)", 255, (0, 255, 1))
],
[],
scale_level_save
)
# Main function
main()
- Paste it into a text file
- Save it with a
.py
extension
- Put this file on your
C:\Users\YourName\AppData\Roaming\GIMP\2.10\plug-ins
folder (more information below if it doesn't work)
- Start GIMP
- Open all your image files by drag and drop
- Go on Filter → Scale Level and Save
- Choose your options
- Launch the script → all the files are already saved with the 3 operations
- Quit GIMP ignoring the prompts
For systems other than Windows, look at the settings in GIMP:
- Click on Edit
- Click on Preferences
- Go on left pane; at bottom
- Click on Folders
- Click on Plug-ins
- Click on Add a new folder
Successfully tested on GIMP 2.10.36 on Windows 10.