PythonFu在gimpgui中运行,但不是从命令行或批处理运行

2024-05-16 02:33:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用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()

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

非常感谢您的帮助。你知道吗


Tags: imageancontextrgbextrahuepdbset