0

I'm trying to batch edit a number of jpg images using the BIMP batch processor plugin. This works fine with one of my python-fu scripts but not the other. It simply does nothing to the image, but still saves the 'new' version.

However when the 'bad' script is selected from the menu in the gui, it works perfectly.

This is the script that doesn't work in batch:

#!/usr/bin/env python

from gimpfu import *

def remove_colour(image, drawable):

    # start undo
    pdb.gimp_image_undo_group_start(image)

    #select the area by colour

    pdb.gimp_context_set_antialias(1)
    pdb.gimp_context_set_feather(1)
    pdb.gimp_context_set_feather_radius(1.0, 1.0)
    pdb.gimp_context_set_sample_merged(0)
    pdb.gimp_context_set_sample_criterion(0)
    pdb.gimp_context_set_sample_transparent(0)    
    pdb.gimp_context_set_sample_threshold_int(100)

    background = gimpcolor.RGB(255,255,255)
    pdb.gimp_context_set_background(background)

    operation = CHANNEL_OP_REPLACE
    color = gimpcolor.RGB(00,85,202)
    pdb.gimp_image_select_color(image, operation, drawable, color)

    #delete the selected area  
    pdb.gimp_drawable_edit_clear(drawable)   

    #end undo
    pdb.gimp_image_undo_group_end(image)


register(
    "python-fu-remove_colour",
    "Remove a colour",
    "Select by colour then delete",
    "A", "A", "2019",
    "remove_colour",
    "*", # type of image it works on (*, RGB, RGB*, RGBA, GRAY etc...)
    [
        # basic parameters are: (UI_ELEMENT, "variable", "label", Default)
        (PF_IMAGE, "image", "takes current image", None),
        (PF_DRAWABLE, "drawable", "Input layer", None)
        # PF_SLIDER, SPINNER have an extra tuple (min, max, step)
        # PF_RADIO has an extra tuples within a tuple:
        # eg. (("radio_label", "radio_value), ...) for as many radio buttons
        # PF_OPTION has an extra tuple containing options in drop-down list
        # eg. ("opt1", "opt2", ...) for as many options
        # see ui_examples_1.py and ui_examples_2.py for live examples
    ],
    [],
    remove_colour, menu="<Image>/Colors")  # second item is menu location

main()

This is the script that works fine in batch

#!/usr/bin/env python

from gimpfu import *

def saturate2(image, drawable):

    # start undo
    pdb.gimp_image_undo_group_start(image)

    #saturation
    hue_range = 0
    hue_offset = 0
    lightness = 0
    saturation = 100
    overlap = 0
    pdb.gimp_drawable_hue_saturation(drawable, hue_range, hue_offset, lightness, saturation, overlap)
    pdb.gimp_drawable_hue_saturation(drawable, hue_range, hue_offset, lightness, saturation, overlap)

    #end undo
    pdb.gimp_image_undo_group_end(image)


register(
    "python-fu-saturate2",
    "saturate twice",
    "Run full saturation twice",
    "A", "A", "2019",
    "Double Saturate",
    "*", # type of image it works on (*, RGB, RGB*, RGBA, GRAY etc...)
    [
        # basic parameters are: (UI_ELEMENT, "variable", "label", Default)
        (PF_IMAGE, "image", "takes current image", None),
        (PF_DRAWABLE, "drawable", "Input layer", None)
        # PF_SLIDER, SPINNER have an extra tuple (min, max, step)
        # PF_RADIO has an extra tuples within a tuple:
        # eg. (("radio_label", "radio_value), ...) for as many radio buttons
        # PF_OPTION has an extra tuple containing options in drop-down list
        # eg. ("opt1", "opt2", ...) for as many options
        # see ui_examples_1.py and ui_examples_2.py for live examples
    ],
    [],
    saturate2, menu="<Image>/Colors")  # second item is menu location

main()

There are no error messages. The script saves the file in a the correct folder but none of the edits have been made. Again, it works fine when selected from the menu, but in batch mode it doesn't.

Any help greatly appreciated.

almac
  • 1
  • Probably wrong hardcoded arguments to color initializator (`gimpcolor.RGB(00,85,202)`) - in Gimp those are picked from a widget. – ipaleka Jul 15 '19 at 16:07
  • 1) GIMP version, 2.8 or 2.10? 2) I assume you want to replace the color with black or transparency, depending on absence/presence of alpha-channel? 3) since you can write your own scripts, why do you use BIMP? See here for an example of a [BIMP-free batch](https://stackoverflow.com/questions/44430081/how-to-run-python-scripts-using-gimpfu-from-windows-command-line/44435560#44435560). – xenoid Jul 15 '19 at 20:37
  • @xenoid In the end I did actually go for a BIMP-free approach using the code you gave in that answer. Oddly, the problematic script still wouldn't run. I got the 'execution error' message. Again, the other script ran fine. I tried taking the code out of the problem file and putting it in the other one and it worked? Still no clue what the problem with that script was but guess it's resolved now. Thanks! – almac Jul 17 '19 at 10:38
  • @almac https://www.gimp-forum.net/Thread-Debugging-python-fu-scripts-in-Windows – xenoid Jul 17 '19 at 12:03
  • One problem I've run into in the past is that pdb can either mean Plug-In Database, from within GIMP; or Python Debugger (completely different!) outside of it. This is unfortunately included in the base Python 2.7 package on many operating systems, but you can usually get around it by, within your function, including "from gimpfu import pdb" at the very top. You can't know what your end-user's system is like during development—not that well—so this seems best to me. Tell me if this works for you. – Michael Macha Nov 10 '19 at 20:39

0 Answers0