【问题标题】:GIMP: Automatically blur/fade/mask edges of multiple layersGIMP:自动模糊/淡化/遮罩多个图层的边缘
【发布时间】:2018-03-08 16:12:24
【问题描述】:

我有很多不规则边界的图层和背景。我想通过在它们的边界上应用某种过滤器,逐渐将图像“混合”到背景中。有没有办法自动做到这一点?

我尝试的是:

  1. 合并所有层
  2. 选择这个组合图层的背景
  3. 反转选择
  4. 对选区应用羽化
  5. 白色颜色填充选区在蒙版

这种方法有点工作,但我的问题是我有重叠的层。这意味着上述方法将图层的边界淡化到背景,但不会彼此淡化

我从未尝试过在 GIMP 中编写脚本,但如果有人有可行的解决方案,我非常愿意尝试。

【问题讨论】:

  • 这更像是一个一般性的使用问题——一旦你知道要做什么,你就可以编写脚本了。因此,这个问题更适合 superuser.com 或图形设计

标签: gimp alpha-transparency fading


【解决方案1】:

是的 - 可以编写脚本。

基本上,GIMP 中的脚本可以执行通常可以通过 UI 执行的任何操作,有些则不能。

因此,一旦您确定了需要为每个所需层执行的步骤 -

例如,通过具有最大阈值的颜色进行选择并禁止透明度 - (这应该为您提供具有图层可见内容形状的选择)。
然后,收缩、反转和羽化选区 并使用“TRASPARENT_FILL”应用“gimp edit cut”,或者以编程方式“gimp-edit-fill”。 对于这些操作中的每一个,您可以查看help->procedure_browser 下的可用调用。

现在,要创建 GIMP Python 脚本,您需要做的是:

创建一个 Python 2 程序,它将从“gimpfu”模块导入所有内容;将其作为可执行文件放在 GIMPs plug-in folder (check the folders atedit->preferences->folders` 中

在脚本中,您编写主函数和任何其他函数 - 主函数可以将任何 GIMP 对象作为输入参数,例如 Image、Drawable、颜色、调色板、r 只是您想要的字符串和整数 -

然后,您可以适当地调用 register gimpfu.register 函数 - 这将使您的脚本成为插件,在 GIMP 中具有自己的菜单选项。通过调用 gimpfu.main() 来完成脚本。

此外,没有“现成”的方法可以在插件中选择一组图层,而不是仅将当前活动的图层作为输入。作为对这些情况的一个非常方便的解决方法,我滥用了“链接”图层标记(单击图层对话框,在可见性图标的右侧将显示一个“链”图标,指示图层是链接)

总而言之,你的插件模板就是:

#! /usr/bin/env python
# coding: utf-8


import gimp
from gimpfu import *


def recurse_blend(img, root, amount):
    if hasattr(root, "layers"):
        # is image or layer group
        for layer in root.layers:
            recurse_blend(img, layer, amount)
        return
    layer = root
    if not layer.linked:
        return # Ignore layers not marked as "linked" in the UI.
    # Perform the actual actions:
    pdb.gimp_image_select_color(img, CHANNEL_OP_REPLACE, layer, (0,0,0))
    pdb.gimp_selection_shrink(img, amount)
    pdb.gimp_selection_invert(img)
    pdb.gimp_selection_feather(img, amount * 2)
    pdb.gimp_edit_clear(layer)


def blend_layers(img, drawable, amount):

    # Ignore drawable (active layer or channel on GIMP)
    # and loop recursively through all layers

    pdb.gimp_image_undo_group_start(img)
    pdb.gimp_context_push()
    try:
        # Change the selection-by-color options
        pdb.gimp_context_set_sample_threshold(1)
        pdb.gimp_context_set_sample_transparent(False)
        pdb.gimp_context_set_sample_criterion(SELECT_CRITERION_COMPOSITE)
        recurse_blend(img, img, amount)
    finally:
        # Try to restore image's undo state, even in the case
        # of a failure in the Python statements.
        pdb.gimp_context_pop()  # restores context
        pdb.gimp_selection_none(img)
        pdb.gimp_image_undo_group_end(img)


register(
    "image_blend_linked_layers_edges",  # internal procedure name
    "Blends selected layers edges",  # Name being displayed on the UI
    "Blend the edges of each layer to the background",
    "João S. O. Bueno",  # author
    "João S. O. Bueno",  # copyright holder
    "2018",              # copyright year(s)
    "Belnd layers edges", # Text for menu options
    "*",                  # available for all types of images
     [
        (PF_IMAGE, "image", "Input image", None),  # Takes active image as input
        (PF_DRAWABLE, "drawable", "Input drawable", None),  # takes active layer as input
        (PF_INT, "Amount", "amount to smooth at layers edges", 5),   # prompts user for integer value (default 5)
    ],
    [],  # no output values
    blend_layers, # main function, that works as entry points
    menu="<Image>/Filters/Layers",  # Plug-in domain (<Image>) followed by Menu position.
    )

main()

【讨论】:

    猜你喜欢
    • 2015-03-26
    • 1970-01-01
    • 1970-01-01
    • 2020-10-18
    • 2012-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-05
    相关资源
    最近更新 更多