5

我想编写一个 Gimp-Python 插件,以便从当前图像中导出所有 SVG 路径。这看起来很简单,但我被 pdb 调用困住了,我可能没有正确调用程序,所以我需要你的帮助。

这是我的代码:

#!/usr/bin/env python

from gimpfu import *

def exportToSvg(img, layer) :
    gimp.pdb.vectors_export_to_file(img,"C:/Users/Public/Documents/output.svg",0)

register(
    "ExportToSvg",    
    "Export all SVG paths",   
    "Export all SVG paths from current image",
    "My Name", 
    "My company", 
    "2015",
    "<Image>/MyScripts/Export to svg", 
    "*", 
    [], 
    [],
    exportToSvg)

main()

打开 Gimp 并加载图像后,当我单击我的插件时,我收到此错误:

调用 « gimp-procedural-db-proc-info » 时出错:找不到过程«vectors-export-to-file »

当我在 Gimp PDB 中搜索时,我可以找到“gimp-vectors-export-to-file”,那么问题是什么?我应该如何调用这个程序?

4

2 回答 2

2

我已将此问题改编为一个 gimp python 插件,该插件将此功能公开为 svg 导出格式。

我已经把它变成了一个要点,欢迎提出请求,要点可能比这个答案更有特色。

https://gist.github.com/thorsummoner/3ad6f806f1c08246f240222a3c0a5c47

将此源复制到 gimp 插件目录(并使其可执行)。

在我的系统上~/.gimp-2.8/plug-ins/file-svg-export.py,在 Windows 上它可能在%appdata%.

#!/usr/bin/env python

# GIMP Plug-in for Simple SVG Exports

# Copyright (C) 2016 by Dylan Grafmyre <thorsummoner@live.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.

# based on an openraster plugin by 
# https://git.gnome.org/browse/gimp/tree/plug-ins/pygimp/plug-ins/file-openraster.py?h=GIMP_2_8_16

import gimpfu

def register_save_handlers():
    gimpfu.gimp.register_save_handler('file-svg-save', 'svg', '')

def save_svg(img, drawable, filename, raw_filename):
    gimpfu.gimp.pdb.gimp_vectors_export_to_file(img, filename, None)

gimpfu.register(
    'file-svg-save', #name
    'save an SVG (.svg) file', #description
    'save an SVG (.svg) file',
    'Dylan Grafmyre', #author
    'Dylan Grafmyre', #copyright
    '2016', #year
    'SVG',
    '*',
    [   #input args. Format (type, name, description, default [, extra])
        (gimpfu.PF_IMAGE, "image", "Input image", None),
        (gimpfu.PF_DRAWABLE, "drawable", "Input drawable", None),
        (gimpfu.PF_STRING, "filename", "The name of the file", None),
        (gimpfu.PF_STRING, "raw-filename", "The name of the file", None),
    ],
    [], #results. Format (type, name, description)
    save_svg, #callback
    on_query = register_save_handlers,
    menu = '<Save>'
)

gimpfu.main()

要简单地使用 File -> Export As,your file.svg

它将所有路径导出到单个 svg 文件。

于 2016-05-17T04:59:15.270 回答
1

你快到了 - “pdb”模块只是在模块级别公开,from gimpfu import *所以不需要这样做gimp.pdb.<procname>- 只是pdb.<procname>(虽然它会工作)。

但真正导致您的错误的是该过程实际上被调用 gimp_vectors_export_to_file- 而不是vectors_export_to_file-

您应该将其称为:

pdb.gimp_vectors_export_to_file(img,"C:/Users/Public/Documents/output.svg",None)

另请注意,对于大多数需要图像项的整数标识符的 PDB 调用,您应该传递一个表示该项的适当 Python 对象。用于保存单个 Vectors 的“Vectors”对象是通过调用其他 PDB 函数获得的。为了保存所有向量,而不是函数描述中列出的“0”,传递None

注意:您可以使用 Python 交互式控制台访问filters->python->console- 如果您首先以交互方式测试 pdb 调用和图像操作,则为这些插件和脚本编写代码会容易得多。

要在交互式控制台中获取对图像的引用,请键入:

img = gimp.image_list()[0]

于 2015-03-20T16:29:24.233 回答