5

現在の画像からすべての SVG パスをエクスポートするために、Gimp-Python プラグインを作成したいと考えています。これは非常に単純に思えますが、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 » を呼び出す際のエラー: Procedure« vectors-export-to-file » が見つかりません

Gimp PDB で検索すると、「gimp-vectors-export-to-file」が見つかりますが、何が問題なのですか? このプロシージャをどのように呼び出す必要がありますか?

4

2 に答える 2

2

この質問を、この機能を svg エクスポート形式として公開する gimp python プラグインに適合させました。

私はそれを要旨にしました。プルリクエストを歓迎します。要点はこの回答よりも機能的である可能性があります。

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()

単純に [ファイル] -> [名前を付けてエクスポート] を使用するには、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 オブジェクトを渡す必要があることに注意してください。個々の Vector を保存するための「Vectors」オブジェクトは、他の PDB 関数を呼び出すことによって取得されます。すべての vector を保存するには、関数の説明に記載されている「0」の代わりに を渡しNoneます。

注意: Python インタラクティブ コンソールを使用してアクセスできますfilters->python->console。最初に pdb 呼び出しと画像操作をインタラクティブにテストすると、これらのプラグインとスクリプトのコーディングがはるかに簡単になります。

インタラクティブ コンソールでイメージへの参照を取得するには、次のように入力します。

img = gimp.image_list()[0]

于 2015-03-20T16:29:24.233 に答える