我有很多层有不规则的边界,和一个背景。我想“融入”图像到背景,通过在他们的边界上应用某种过滤器,逐步。有办法自动做到这一点吗?
我试过的是:
这种方法是可行的,但我的问题是我有重叠的层。这意味着上面的方法会将层的边界淡出到背景,而不是彼此之间。
我从未尝试过用GIMP编写脚本,但如果有人有可行的解决方案,我更愿意尝试它。
发布于 2018-03-09 15:08:16
是的-可以写成剧本。
基本上,GIMP中的脚本可以通过UI执行任何通常可能的操作,而有些则不是。
所以,一旦你确定了你需要为每个想要的层执行的步骤-
例如,根据颜色选择最大的阈值和透明度-(这应该给你一个选择与图层的可见内容的形状)。
然后,收缩,倒置和羽毛的选择和应用"gimp编辑剪切“,或编程”gimp-编辑-填充“,与"TRASPARENT_FILL”。对于这些操作中的每一个,您都可以检查help->procedure_browser
下的avaliable调用。
现在,要创建一个GIMP Python脚本,您必须做的是:
创建一个Python2程序,它将从"gimpfu“模块导入所有内容;将其作为一个可在GIMPs plug-in folder (check the folders at
edit->preferences->folders`中执行的
在脚本中,您可以编写主函数和任何其他函数--主函数可以将任何GIMP对象作为输入参数,如图像、可绘制、颜色、调色板、简单字符串和整数-
然后对寄存器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()
https://stackoverflow.com/questions/49177633
复制相似问题