Export all SVG paths using the Python Gimp plugin

I want to write a Gimp-Python plugin to export all SVG paths from the current image. It seems pretty simple, but I'm stuck in pdb calls, I can't call the procedures correctly, so I need your help.

Here is my code:

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

After opening Gimp and loading the image, when I click on my plugin, I get this error:

An error occurred while calling "gimp-procedureural-db-proc-info": The procedure "vectors-export-to-file" was not found

When I search in Gimp PDB, I can find "gimp-vectors-export-to-file", what is the problem? What can I call this procedure?

+4
source share
2 answers

- "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, . "" PDB. "0", , None.

NB: Python, , filters->python->console - , pdb .

, :

img = gimp.image_list()[0]

+1

gimp python, svg.

, , , .

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

gimp ( ).

, ~/.gimp-2.8/plug-ins/file-svg-export.py, - %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.

+1

All Articles