GIMP Python - 填充路径/矢量

2024-03-29 07:44:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试开发一个可以在打开的SVG文件上运行的脚本。我想迭代所有路径,并用任意颜色填充路径(稍后我将替换这部分代码)。第一步只是在路径上迭代,我似乎不知道该怎么做。我的代码如下-为什么我没有看到任何路径被迭代?在

#!/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()

我还尝试了许多不同的方法,包括使用更简单的迭代方法,比如:

^{pr2}$

但不管我做了什么,我似乎都无法得到迭代的证据。在

我在Windows 10 64位上使用gimp 2.10.6。在


Tags: thepath代码image路径mainwithall
1条回答
网友
1楼 · 发布于 2024-03-29 07:44:23

这是个陷阱。。。pdb.gimp_image_get_vectors(image)返回路径的整数ID列表,但是后面的调用需要一个gimp.Vectors对象。在

image.vectors实际上是gimp.Vectors的列表,您可以用

for vector in image.vectors:

更多问题:

  • 在register()中声明两个参数,但在函数中有三个。实际上,您不需要路径参数,因为您无论如何都要迭代它们。在
  • 函数的layer参数是调用插件时的活动层,通常是要绘制的层
  • gimp-edit-fill接受颜色源而不是颜色。当你继续你的代码,你将不得不设置前景颜色,并推/弹出上下文
  • CHANNEL-OP-REPLACE不是有效的Python符号,在Python中应该使用CHANNEL_OP_REPLACE(带下划线)

python脚本的两个集合here和{a2}。在

如果您在Windows下,一些调试脚本的提示here

包含修复程序的代码:

^{pr2}$

您可以通过绘制“笔划”使您的代码更加用户友好(这样您就有了一条包含多个笔划的路径)。如果要对笔划进行单独选择,可以将其复制到临时路径。可以在上面集合中的一些脚本中找到此代码。在

相关问题 更多 >