是的 - 可以编写脚本。
基本上,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()