GIMP Python-用颜色填充路径/向量
我正在尝试开发一个可以在打开的SVG文件上运行的脚本。我希望迭代所有路径,并用任意颜色填充路径(稍后我将替换这部分代码)。这的第一阶段只是在路径上迭代,我似乎不知道怎么做。我的代码如下-为什么我没有看到任何路径被迭代GIMP Python-用颜色填充路径/向量,python,gimp,gimpfu,Python,Gimp,Gimpfu,我正在尝试开发一个可以在打开的SVG文件上运行的脚本。我希望迭代所有路径,并用任意颜色填充路径(稍后我将替换这部分代码)。这的第一阶段只是在路径上迭代,我似乎不知道怎么做。我的代码如下-为什么我没有看到任何路径被迭代 #!/usr/bin/env python # -*- coding: utf-8 -*- from gimpfu import * def plugin_main(image, layer, path): vectors_count, vectors = pdb.gi
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gimpfu import *
def plugin_main(image, layer, path):
vectors_count, vectors = pdb.gimp_image_get_vectors(image)
for n in vectors:
pdb.gimp_image_select_item(image,CHANNEL-OP-REPLACE,n)
foreground = pdb.gimp_context_get_foreground()
pdb.gimp_edit_fill(image.layers[0], foreground)
register(
"create_polygon_art",
"Fills all the paths with the average color within path",
"Fills all the paths with the average color within path",
"Bryton Pilling",
"Bryton Pilling",
"2018",
"<Image>/Filters/Fill all paths with average color",
"RGB*, GRAY*",
[],
[],
plugin_main
)
main()
但是,无论我尝试什么,我似乎都无法获得在路径上进行迭代的证据
我正在Windows 10 64位上使用gimp 2.10.6。这是一个陷阱
pdb.gimp\u image\u get\u vectors(image)
返回路径的整数ID列表,但后面的调用需要一个gimp.vectors
对象
image.vectors
实际上是一个gimp.vectors
列表,您可以使用
for vector in image.vectors:
更多问题:
- 在register()中声明了两个参数,但在函数中有三个。实际上,您不需要path参数,因为您无论如何都要迭代它们
- 函数的layer参数是调用插件时的活动层,通常是要绘制的层
采用颜色源,而不是颜色。当您进一步使用代码时,您必须设置前景色,并按下/弹出上下文gimp编辑填充
不是有效的Python符号,在Python中应使用CHANNEL-OP-REPLACE
(带下划线)CHANNEL\u OP\u REPLACE
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gimpfu import *
def plugin_main(image, layer):
for p in image.vectors:
pdb.gimp_image_select_item(image,CHANNEL_OP_REPLACE,p)
pdb.gimp_edit_fill(layer, FOREGROUND_FILL)
register(
"create_polygon_art",
"Fills all the paths with the average color within path",
"Fills all the paths with the average color within path",
"Bryton Pilling",
"Bryton Pilling",
"2018",
"<Image>/Test/Fill all paths with average color",
"RGB*, GRAY*",
[],
[],
plugin_main
)
main()
#/usr/bin/env python
#-*-编码:utf-8-*-
从gimpfu进口*
def插件_主(图像,层):
对于image.vectors中的p:
pdb.gimp_图像_选择_项(图像、通道_操作_替换、p)
pdb.gimp_编辑_填充(图层、前景_填充)
登记册(
“创建多边形艺术”,
“用路径中的平均颜色填充所有路径”,
“用路径中的平均颜色填充所有路径”,
“布莱顿起球”,
“布莱顿起球”,
"2018",
“/Test/用平均颜色填充所有路径”,
“RGB*,灰色*”,
[],
[],
主插件
)
main()
您可以通过绘制“笔划”(这样您就有了一条包含多个笔划的路径)使您的代码更加用户友好。如果希望对笔划进行单独选择,可以将其复制到临时路径。这方面的代码可以在上述集合中的一些脚本中找到。谢谢!我发现需要下划线的CHANNEL_OP_REPLACE导致脚本无法工作,修复此问题意味着脚本将运行。提到的其他几点非常有帮助,谢谢。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gimpfu import *
def plugin_main(image, layer):
for p in image.vectors:
pdb.gimp_image_select_item(image,CHANNEL_OP_REPLACE,p)
pdb.gimp_edit_fill(layer, FOREGROUND_FILL)
register(
"create_polygon_art",
"Fills all the paths with the average color within path",
"Fills all the paths with the average color within path",
"Bryton Pilling",
"Bryton Pilling",
"2018",
"<Image>/Test/Fill all paths with average color",
"RGB*, GRAY*",
[],
[],
plugin_main
)
main()