I want to write a Gimp-Python plugin in order to export all SVG paths from the current image. This seems quite simple but I am stuck with pdb calls, I may not be calling 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 an image, when I click on my plugin i receive this error:
Error when calling « gimp-procedural-db-proc-info » : Procedure« vectors-export-to-file » not found
When I search in Gimp PDB, I can find"gimp-vectors-export-to-file" so what is the problem ? How should I call this procedure ?
I've adapted this question into a gimp python plugin that exposes this functionality as the svg export format.
I have made it into a gist, pull requests welcome, the gist may be more featureful than this answer.
https://gist.github.com/thorsummoner/3ad6f806f1c08246f240222a3c0a5c47
Copy this source into the gimp plugin directory (and make it executable).
On my system that is ~/.gimp-2.8/plug-ins/file-svg-export.py
, on windows its probably somewhere in %appdata%
.
#!/usr/bin/env python
# GIMP Plug-in for Simple SVG Exports
# Copyright (C) 2016 by Dylan Grafmyre <[email protected]>
#
# 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()
To use simply File -> Export As, your file.svg
It will export all paths to a single svg file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With