Python-Fu在Gimp gui中运行,但不能从命令行或批处理中运行

时间:2019-07-15 15:51:14

标签: python windows command-line gimp python-fu

我正在尝试使用BIMP批处理处理器插件批量编辑许多jpg图像。这对我的python-fu脚本之一有效,但对另一个不起作用。它只是对图像不执行任何操作,但仍保存“新”版本。

但是,当从gui菜单中选择“不良”脚本时,它会完美运行。

这是不能批量使用的脚本:

#!/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()

这是可以批量工作的脚本

#!/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()

没有错误消息。该脚本将文件保存在正确的文件夹中,但未进行任何编辑。再次,当从菜单中选择它时,它可以正常工作,但是在批处理模式中,它却不能。

任何帮助都将不胜感激。

0 个答案:

没有答案