我正在尝试为GIMP编写一个Python-Fu插件,但添加4个以上的输入参数(包括Image和Drawable参数)将导致脚本根本无法运行。我已尝试使用各种输入参数类型,它们都产生相同的结果。有没有人知道为什么会这样?我错过了一些明显的东西吗?
register(
"python_fu_guide_maker",
"Guide Maker",
"Creates guides with specified spacing.",
"MrKagouris", "", "2017",
"Guide Maker",
"*",
[
(PF_IMAGE, "image", "Input Image", None),
(PF_DRAWABLE, "drawable", "Input Layer", None),
(PF_INT, "hspace", "Horizontal Spacing", None),
(PF_INT, "vspace", "Vertical Spacing", None),
(PF_BOOL, "percent", "By percent?", None)
],
[],
guide_maker,
menu="<Image>/Image/Guides"
)
编辑:
下面是完整的,功能齐全的脚本,包括Python代码。
#!/usr/bin/env python
from gimpfu import *
def guide_by_num(image, hspace, vspace):
imageHeight = pdb.gimp_image_height(image)
imageWidth = pdb.gimp_image_width(image)
if (hspace <= 0 or vspace <= 0):
return # Input validity check.
hGuides = int(imageHeight/hspace) # Calculates the
vGuides = int(imageWidth/vspace) # number of guides.
for i in range(2):
pdb.gimp_image_add_hguide(image, i * imageHeight) # Adds guides to
pdb.gimp_image_add_vguide(image, i * imageWidth) # image edges.
for i in range(1, hGuides): # Adds the horizontal
pdb.gimp_image_add_hguide(image, i * hspace) # guides.
for i in range(1, vGuides): # Adds the vertical
pdb.gimp_image_add_vguide(image, i * vspace) # guides.
def guide_by_percent(image, hspace, vspace): #Not used.
imageHeight = pdb.gimp_image_height(image)
imageWidth = pdb.gimp_image_width(image)
hspace = int(hspace * (imageWidth * 0.01))
vspace = int(vspace * (imageHeight * 0.01))
if (hspace <= 0 or vspace <= 0):
return
hGuides = int(imageHeight/hspace)
vGuides = int(imageWidth/vspace)
for i in range(2):
pdb.gimp_image_add_hguide(image, i * imageHeight)
pdb.gimp_image_add_vguide(image, i * imageWidth)
for i in range(1, hGuides):
pdb.gimp_image_add_hguide(image, i * hspace)
for i in range(1, vGuides):
pdb.gimp_image_add_vguide(image, i * vspace)
def guide_maker(image, drawable, hspace, vspace):
guide_by_num(image, hspace, vspace)
register(
"python_fu_guide_maker",
"Guide Maker",
"Creates guides with specified spacing.",
"MrKagouris", "", "2017",
"Guide Maker",
"*",
[
(PF_IMAGE, "image", "Input Image", None),
(PF_DRAWABLE, "drawable", "Input Layer", None),
(PF_INT, "hspace", "Horizontal Spacing", None),
(PF_INT, "vspace", "Vertical Spacing", None),
#(PF_BOOL, "percent", "By percent?", None)
],
[],
guide_maker,
menu="<Image>/Image/Guides"
)
main()