所以我正在用python制作我的第一个gimp插件。到目前为止,它正在正常工作:
它首先为边框创建一个辅助层,然后调整它的大小以适合画布,然后选择活动层的轮廓(“正常”GIMP 中的 Alpha 到选择),为其设置边框,删除活动层的轮廓到保留图层上的像素,然后将边框增加1,锐化并填充它。
但有时它似乎选择了整个图层而不是它的轮廓,这是一个 GIMP 错误,还是我做错了什么?
#!/usr/bin/env python
from gimpfu import *
import time
def white_box(img, drawable, thickness = 5, layer = None):
pdb.plug_in_autocrop_layer(img, drawable)
# layer = pdb.gimp_image_get_active_layer(img)
box = pdb.gimp_layer_new(img, 1, 1, 1, pdb.gimp_item_get_name(layer) + "_white box", 100, 0)
pdb.gimp_image_insert_layer(img, box, None, -1)
pdb.gimp_layer_resize_to_image_size(box)
# pdb.gimp_layer_resize_to_image_size(layer)
pdb.gimp_image_select_item(img, 0, layer)
pdb.gimp_message("Selected layer")
# pdb.gimp_edit_fill(drawable, 2)
time.sleep(1)
pdb.gimp_selection_border(img, thickness)
pdb.gimp_message("Selected a border with a thickness of " + str(thickness))
time.sleep(1)
pdb.gimp_image_select_item(img, 1, layer)
pdb.gimp_message("Removed layer from selection")
time.sleep(1)
pdb.gimp_selection_grow(img, 1)
pdb.gimp_message("Grew selection")
time.sleep(1)
pdb.gimp_selection_sharpen(img)
pdb.gimp_message("Sharpened")
time.sleep(1)
pdb.gimp_image_set_active_layer(img, box)
pdb.gimp_edit_fill(pdb.gimp_image_get_active_drawable(img), 2)
pdb.plug_in_autocrop_layer(img, drawable)
pdb.plug_in_autocrop_layer(img, pdb.gimp_image_get_active_drawable(img))
register(
"python_fu_white_box",
"Create White Box",
"Create a white box around active layer",
"Misha Smit",
"Misha Smit",
"2018",
"White Box...",
"RGBA", # Create a new image, don't work on an existing one
[
(PF_IMAGE, "img", "Image", None),
(PF_DRAWABLE, "drawable", "Drawable", None),
(PF_INT, "thickness", "Box Thickness", 5),
(PF_LAYER, "layer", "LAYER:", None)
],
[],
white_box, menu="<Image>/Filters/Render")
main()