4
\$\begingroup\$

I have a few thousand images that I want to apply the exact same color curve adjustment to. Is there a way to do this in GIMP? I found this How can I get a uniform white balance on a batch of JPEG images? but this is for automatic levels adjustment rather than applying the same adjustment to every image, and I do not understand what it is or how to modify it.

I've saved a preset adjustment in "Adjust Color Curves" in GIMP, but how do I apply this to every image other than just going through everyone and clicking on it?

\$\endgroup\$

2 Answers 2

4
\$\begingroup\$

For anyone else wanting to do this I figured it out.

First I got the color curve I wanted, and clicked the plus to "Save the current settings as named preset"

Then next to the plus I pressed Manage presets -> export current settings to file

Then I downloaded CurveBatch from here http://gimpfr.org/contrib_photolabo.php

Then in GIMP I clicked edit->Preferences->Folders->Plug-ins to find where plug-ins are saved.

I then saved CurveBatch here after extracting it.

Then for GIMP 2.10 I had to change the CurveBatch plug-in (photolab_curvebatch) slightly

I changed

  if lines[0] == "# GIMP curves tool settings\n":

to

  if lines[0] == "# GIMP 'Curves' settings\n":

As GIMP 2.10 changed the first line that indicates it is a curve file (Why anyone would think for a second to do this and break backwards compatibility for no reason I do not know)

Then I pressed Filters -> Script-fu -> refresh scripts

Then I closed GIMP and reopened it.

Then the script now showed up in filters, I pressed Filters->PhotoLab->Batch corrections->curve

I chose the folder my images are in, their extension and the curve file that I exported previously.

This then applied the curves to all of my pictures as I wanted.

\$\endgroup\$
7
  • 1
    \$\begingroup\$ Why anyone would think for a second to do this and break backwards compatibility for no reason I do not know The script you use was written for Gimp 2.6 and is 11 years old. It also hard-codes file locations "~/.gimp-2.6" that are version-dependent. \$\endgroup\$
    – xenoid
    May 3, 2020 at 13:05
  • \$\begingroup\$ Filters -> Script-fu -> refresh scripts not useful here; it only refreshes scripts. Python executables are plugins, you have to restart Gimp to have them taken in account. \$\endgroup\$
    – xenoid
    May 3, 2020 at 13:10
  • \$\begingroup\$ @xenoid"The script you use was written for Gimp 2.6 and is 11 years old. " It works fine with just this individual line changed to match the title of the curve file. There is absolutely no reason for this title to have been changed, and the only possible result of changing it is breaking backwards compatibility. \$\endgroup\$ May 3, 2020 at 14:27
  • \$\begingroup\$ The change saves 3 bytes per file. It adds up. \$\endgroup\$
    – xiota
    May 3, 2020 at 21:53
  • \$\begingroup\$ @xiota No, it does not. A space saving of 0.01% does not add up. How many curve files do you think even the most prolific of photographers use? No-one is attempting to optimise to save such a trivial amount of space (particularly obviously not the intention here considering the superfluous apostrophes added). \$\endgroup\$ May 3, 2020 at 22:35
0
\$\begingroup\$

To apply curves on all images:

  1. Copy this GIMP python-fu script:
#!/usr/bin/env python

from gimpfu import *

def curves_in_all_images(dummy_image, dummy_drawable, in_1, out_1, in_2, out_2, in_3, out_3, in_4, out_4, in_5, out_5):
    pdb.gimp_context_push()
    # 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]
        pdb.gimp_progress_update((i * 1.0) / image_number)
        pdb.gimp_progress_set_text("Processing image #" + str(i + 1) + " over " + str(image_number) + "...")

        # Remember the image type
        mode = current_image.base_type

        if mode != RGB:
            pdb.gimp_convert_rgb(current_image)
        current_drawable = current_image.active_layer

        # Curve the layer
        points = [in_1, out_1, in_2, out_2, in_3, out_3, in_4, out_4, in_5, out_5]
        pdb.gimp_curves_spline(current_drawable, HISTOGRAM_VALUE, len(points), points)

        #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)

        # Save the image file
        filename = pdb.gimp_image_get_filename(current_image)
        pdb.gimp_file_save(current_image, current_drawable, filename, '?')
    
    # Refresh the image to see the changes
    pdb.gimp_context_pop()
    pdb.gimp_displays_flush()

# Define the parameters for the script
register(
    "python_fu_curves_in_all_images",
    "Curves on all images",
    "Curves on all images and save; identical values will be ignored",
    "Fabrice TIERCELIN",
    "Fabrice TIERCELIN",
    "2024",
    "<Image>/Filters/Colors/Curves on all images",
    "*",
    [
        (PF_FLOAT, "in_1", "In 1", 0.0),
        (PF_FLOAT, "out_1", "Out 1", 0.0),
        (PF_FLOAT, "in_2", "In 2", 0.0),
        (PF_FLOAT, "out_2", "Out 2", 0.0),
        (PF_FLOAT, "in_3", "In 3", 0.0),
        (PF_FLOAT, "out_3", "Out 3", 0.0),
        (PF_FLOAT, "in_4", "In 4", 0.0),
        (PF_FLOAT, "out_4", "Out 4", 0.0),
        (PF_FLOAT, "in_5", "In 5", 255.0),
        (PF_FLOAT, "out_5", "Out 5", 255.0),
    ],
    [],
    curves_in_all_images
)

# Main function
main()
  1. Paste it into a text file
  2. Save it with a .py extension
  3. Put this file on your C:\Users\YourName\AppData\Roaming\GIMP\2.10\plug-ins folder (more information below if it doesn't work)
  4. Start GIMP
  5. Open all your image files by drag and drop
  6. Go on FilterColorsCurves on all images
  7. Fill as many points as you need between the 5 ones; leave those useless
  8. Launch the script → all the files are already saved with the curves applied
  9. Quit GIMP ignoring the prompts

For systems other than Windows, look at the settings in GIMP:

  1. Click on Edit
  2. Click on Preferences
  3. Go on left pane; at bottom
  4. Click on Folders
  5. Click on Plug-ins
  6. Click on Add a new folder

Successfully tested on GIMP 2.10.36 on Windows 10.

PS: If you need more points, you can easily edit the script. Then restart GIMP.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.