You are not logged in.
I have inkscape, gimp, and imagemagick installed on my arch64 system and I need to render a PNG from an SVG via command-line. I'd like to be able to specify...
-location of SVG
-output location of PNG
-dpi
-anti-aliasing
Does anyone know a way to do this?
Offline
It appears that Inkscape can do most, if not all of this, currently.
Offline
Search for convert from imagemagick.
Offline
http://inkscape-forum.andreas-s.net/topic/133909
Last edited by arch0r (2008-12-30 17:34:48)
Offline
I have tried svg2png once but it messed up one of my svgs (it rendered fine in firefox, so I'm not sure what was wrong)
Offline
Hrm... I am trying imagemagick but am having a weird loss of colour:
SVG: http://norpass.com/angle.svg
Command: "convert angle.svg angle.png"
PNG: http://norpass.com/angle.png
Any ideas?
Offline
Hrm... I am trying imagemagick but am having a weird loss of colour:
SVG: http://norpass.com/angle.svg
Command: "convert angle.svg angle.png"
PNG: http://norpass.com/angle.png
Any ideas?
I'm seeing it too, even with 100% png quality. Do you intend to do a lot of these conversions? If so, do you have GIMP installed and are you interested in GIMP Python scripts as a solution?
Offline
Yes; if gimp can do it via command-line and produce an image like what firefox 3 renders of the svg, that would be great.
Offline
And with inkscape (using "inkscape -f angle.svg -e angle.png") the red line doesn't show up at all... How can I do it with GIMP, Skottish? thanks.
Offline
I tried importing the angle.svg into gimp and found that it also ignores the red line... Maybe I will just live with imagemagick's output.
Offline
Here's a start anyway. It's been a while since I've done anything like this. Currently it reads all image files of a certain pattern out of the current directory (.svg, .jpg, .tif, whatever GIMP can read), converts them to the default png values, and outputs them to some directory that you specify. I'll keep trying to refine it:
#! /usr/bin/env python
from gimpfu import *
import glob
import os
def svgtopng(file_pattern, output_directory):
file_list=glob.glob(file_pattern)
for file_name in file_list:
image = pdb.gimp_file_load(file_name, file_name)
drawable = pdb.gimp_image_get_active_layer(image)
file_name = output_directory + "/" + os.path.splitext(file_name)[0] + ".png"
pdb.file_png_save_defaults(image, drawable, file_name, file_name)
pdb.gimp_image_delete(image)
register(
"svgtopng", "", "", "", "", "",
"<Toolbox>/Xtns/Languages/Python-Fu/svgtopng", "",
[
(PF_STRING, "file_name", "file_name", "file_name"),
(PF_STRING, "output_directory", "output_directory", "output_directory")
],
[],
svgtopng
)
main()
You call it from the directory of your svg files by this. I'll just call the output directory /home/tony5429/output:
gimp -inbdf '(python-fu-svgtopng RUN-NONINTERACTIVE "*.svg" "/home/tony5429/output")''(gimp-quit 1)'
There is absolutely no error checking here. Also, you need to put this file somewhere where GIMP can find it. Call it svgtopng.py, put in the plugins folder ~/.gimp-2.6/plug-ins, and make sure that it's executable.
Offline
Thanks for your help. However, I received the following error when trying your script:
[karam@nikolai ~]$ cd svgtest/
[karam@nikolai svgtest]$ gimp -inbdf '(python-fu-svgtopng RUN-NONINTERACTIVE "*.svg" "/home/karam/output")''(gimp-quit 1)'
/usr/lib/gimp/2.0/plug-ins/help-browser: error while loading shared libraries: libwebkit-1.0.so.1: cannot open shared object file: No such file or directory
(gimp:5663): LibGimpBase-WARNING **: gimp: gimp_wire_read(): error
File "/home/karam/.gimp-2.6/plug-ins/svgtopng.py", line 12
image = pdb.gimp_file_load(file_name, file_name)
^
IndentationError: expected an indented block
(gimp:5663): LibGimpBase-WARNING **: gimp: gimp_wire_read(): error
batch command experienced an execution error
Offline
Sorry about. It looks like it didn't copy and paste well. I'll edit the above post and it should be fine.
--EDIT--
It's the forum. You need to indent all of the lines starting with image and ending in pdb.gimp_image_delete. I'm using four spaces as indentation.
Offline
Hm...Now I'm getting this error:
[karam@nikolai svgtest]$ gimp -inbdf '(python-fu-svgtopng RUN-NONINTERACTIVE "*.svg" "/home/karam/output")''(gimp-quit 1)'
/usr/lib/gimp/2.0/plug-ins/help-browser: error while loading shared libraries: libwebkit-1.0.so.1: cannot open shared object file: No such file or directory
(gimp:5756): LibGimpBase-WARNING **: gimp: gimp_wire_read(): error
[karam@nikolai svgtest]$
Offline
Hm...Now I'm getting this error:
[karam@nikolai svgtest]$ gimp -inbdf '(python-fu-svgtopng RUN-NONINTERACTIVE "*.svg" "/home/karam/output")''(gimp-quit 1)' /usr/lib/gimp/2.0/plug-ins/help-browser: error while loading shared libraries: libwebkit-1.0.so.1: cannot open shared object file: No such file or directory (gimp:5756): LibGimpBase-WARNING **: gimp: gimp_wire_read(): error [karam@nikolai svgtest]$
Your getting an error about not having libwebkit installed. Can you start GIMP normally?
Also, the script won't output any information unless it fails. If you want some sort of confirmation, put a line like this after pdb.gimp_image_delete(image). Use the same indentation:
print file_name + " saved."
Offline
You're right, I get that error every time I load gimp. The script did create angle.png in the output directory - however, the red line of the graph is missing completely. Are you able to use the angle.svg (http://norpass.com/angle.svg) to produce an angle.png with the red line?
Offline
Yes. The test file that I used is yours (just retested). The output png that I get is a transparent image with the graph intact. The red lines are there and it doesn't suffer from the gray artifacts that convert was producing.
Offline
Weird...Maybe I am using an outdated version of Gimp or something. When I get internet again on that machine (I've only got wireless here and that machine only has ethernet), I'll do a system upgrade and try your script again. Thanks for all your help!
Offline