Generating svg images using convert "command line"
Generating svg images using convert "command line"
Hello,
I'm using ImageMagick command line tool (convert) to generate svg images.
First, I tried this command to generate an image with two circle
convert -size 100x100 -draw 'circle 20,20 10,10' -draw 'circle 30,30 50,50' xc: test.svg
It worked correctly but it generated the last circle only
I changed it to
convert -size 100x100 -draw 'circle 20,20 10,10 circle 30,30 50,50' xc: test.svg
and it generated the two circles correctly. However, it didn't respect any of the attributes like fill and stroke. The resulted circles were always black and solid.
My questions are
1) Do I really have to write all my drawing commands in one draw argument (like the second example)?
2) Can I use graphics settings like stroke, strokewidth and fill to draw svg images? how?
3) Can I use DIFFERENT colors for the same svg image? how?
I'm running this version
Version: ImageMagick 6.5.4-2 2009-07-07 Q8 OpenMP http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC
Which is compiled from source on my Ubuntu 9.04 machine.
Thanks in advance.
I'm using ImageMagick command line tool (convert) to generate svg images.
First, I tried this command to generate an image with two circle
convert -size 100x100 -draw 'circle 20,20 10,10' -draw 'circle 30,30 50,50' xc: test.svg
It worked correctly but it generated the last circle only
I changed it to
convert -size 100x100 -draw 'circle 20,20 10,10 circle 30,30 50,50' xc: test.svg
and it generated the two circles correctly. However, it didn't respect any of the attributes like fill and stroke. The resulted circles were always black and solid.
My questions are
1) Do I really have to write all my drawing commands in one draw argument (like the second example)?
2) Can I use graphics settings like stroke, strokewidth and fill to draw svg images? how?
3) Can I use DIFFERENT colors for the same svg image? how?
I'm running this version
Version: ImageMagick 6.5.4-2 2009-07-07 Q8 OpenMP http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC
Which is compiled from source on my Ubuntu 9.04 machine.
Thanks in advance.
Re: Generating svg images using convert "command line"
This will work for png but not for svg - you just get one black circle!
With this you get the two circles but they are both black.
From the ImageMagick website:
Code: Select all
convert -size 200x200 xc:none -fill red -draw "circle 20,20 10,10" -stroke black -strokewidth 10 -fill blue -draw "circle 100,100 50,50" test.png
Code: Select all
convert -size 200x200 xc:none -fill red -draw "circle 20,20 10,10 circle 100,100 50,50" test.svg
From Anthonys examples: http://www.imagemagick.org/Usage/draw/#svgSVG RW Scalable Vector Graphics Requires libxml2 and freetype-2. Note that SVG is a complex specification and support for the specification in ImageMagick is not complete.
Re: Generating svg images using convert "command line"
Thanks Bonzo for your reply. This was really helpful.
Do you know another tool that can generate svg images?
I need to generate svg images from ns2 nam trace files.
Simply I have a list of x,y coordinates and I need to generate some vector images from them like:
drawing circles at node points
draw lines between nearby points
draw coverage circles (centered at node points and of radius r)
...
and other simple images. Colors are important because they distinguish working Vs non-working nodes and active Vs non-active links.
I can generate png files with success but I need to make a high quality report supported with vector images.
Thanks a lot for your efforts
Do you know another tool that can generate svg images?
I need to generate svg images from ns2 nam trace files.
Simply I have a list of x,y coordinates and I need to generate some vector images from them like:
drawing circles at node points
draw lines between nearby points
draw coverage circles (centered at node points and of radius r)
...
and other simple images. Colors are important because they distinguish working Vs non-working nodes and active Vs non-active links.
I can generate png files with success but I need to make a high quality report supported with vector images.
Thanks a lot for your efforts
Re: Generating svg images using convert "command line"
Try inkscape.
Re: Generating svg images using convert "command line"
I use inkscape and it has a very user friendly interface.
What I need is an API to draw vector images. I thought that ImageMagick would help me with this as it has a very powerful and simple API. I can't draw 500 images each having 100 circles at certain locations (x,y) using the mouse. However, I can make a ruby script that does the job.
Any ideas?
What I need is an API to draw vector images. I thought that ImageMagick would help me with this as it has a very powerful and simple API. I can't draw 500 images each having 100 circles at certain locations (x,y) using the mouse. However, I can make a ruby script that does the job.
Any ideas?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Generating svg images using convert "command line"
not an expert, but did you install RSVG and freetype delegates.
see http://www.imagemagick.org/Usage/draw/
http://www.imagemagick.org/Usage/draw/#svg
hopefully Anthony can answer most of your questions once he gets online
see http://www.imagemagick.org/Usage/draw/
http://www.imagemagick.org/Usage/draw/#svg
hopefully Anthony can answer most of your questions once he gets online
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Generating svg images using convert "command line"
IM is a raster (pixel array) image processor, and as such when the IM draw command is used
it 'draws' on a raster image. It does NOT generate SVG vectors!
When you ask IM to generate a SVG version of an image it does so by calling the AutoTrace library. This is a bitmap to vector graphic converter, but it has some limitations.
Compare the results of the scripts "segment_image" and "segment_via_svg" in the IM Examples Scripts area http://www.imagemagick.org/Usage/scripts/ using the image http://www.imagemagick.org/Usage/images/segment.png
This makes a good example of how good (or bad) the raster to SVG conversion is...
segment_image
segment_via_svg
it 'draws' on a raster image. It does NOT generate SVG vectors!
When you ask IM to generate a SVG version of an image it does so by calling the AutoTrace library. This is a bitmap to vector graphic converter, but it has some limitations.
- First it does NOT handle anti-aliased pixels very well. You are better off thresholding the image so as to brovide a clean edge for AutoTrace to trace other regionas and shapes of color.
- Second it will only generate complex polygons of the shape. If you ask for a circle you will NOT get a circle, but a rough polygonal representation of a circle, appropriate for the scale of the image being converted.
- Third it has to make decisions about weathe rto make a smooth curve or a sharp point when the direction of a shapes edge changes. There are many rules and options for this which generally work well. However in some situations I have found a need to 'tweek' the 'angle' option to make
a sharp change instead of a curve for some images.
Compare the results of the scripts "segment_image" and "segment_via_svg" in the IM Examples Scripts area http://www.imagemagick.org/Usage/scripts/ using the image http://www.imagemagick.org/Usage/images/segment.png
This makes a good example of how good (or bad) the raster to SVG conversion is...
segment_image
segment_via_svg
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Generating svg images using convert "command line"
Thanks all for your help.
For now I'll use ImageMagick to generate raster images.
Meanwhile, I'll try to search/develop libraries that allow generating svg images. I found that I can write plugins for InkScape in Python. But I search for simpler APIs like RMagick http://rmagick.rubyforge.org/ and QuickMagick http://quickmagick.rubyforge.org/quick_ ... index.html.
For now I'll use ImageMagick to generate raster images.
Meanwhile, I'll try to search/develop libraries that allow generating svg images. I found that I can write plugins for InkScape in Python. But I search for simpler APIs like RMagick http://rmagick.rubyforge.org/ and QuickMagick http://quickmagick.rubyforge.org/quick_ ... index.html.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Generating svg images using convert "command line"
One method I used a VERY long time ago (almost 20 years now but still valid) was to output 'fig' files. The fig vector language used for the 'xfig' is very simple and easy to program. You can then convert that to pdf or svg directly using 'transfig'.
Hmmm oops sorry svg is not available (too new for this old application)
Hmmm oops sorry svg is not available (too new for this old application)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Generating svg images using convert "command line"
Lateral thinking - generate the png with Imagemagick and then convert that to svg with Inkscape or similar ?
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Generating svg images using convert "command line"
SVG does not accept a raster image. it is pure vector.
The autotrace (SVG output from ImageMagick) is the PNG to SVG conversion
and that is essentially what the user was doing, not what he is wanting.
The autotrace (SVG output from ImageMagick) is the PNG to SVG conversion
and that is essentially what the user was doing, not what he is wanting.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
-
- Posts: 10
- Joined: 2019-07-02T18:53:00-07:00
- Authentication code: 1152
Re: Generating svg images using convert "command line"
Why not write the paths in a svg document and then rasterize it to a bitmap (which is safe) ? why do you need to use IM to draw vectors ?I'm using ImageMagick command line tool (convert) to generate svg images.
Did you try using -compose or generating several "files" one for each shape using +clone between parenthesis ? perhaps it will end up joining all shapes in a final one ? (really I have no-idea)This will work for png but not for svg - you just get one black circle!
I was playing with image tracing technologies recently (JavaScript). I'm joining different tracer implementations I've found (so far only 2 in js) in this project:When you ask IM to generate a SVG version of an image it does so by calling the AutoTrace library.
browser/node.js API: https://www.npmjs.com/package/svg-png-converter
command line tool https://www.npmjs.com/package/svg-png-converter-cli
user-friendly playground (WIP) https://cancerberosgx.github.io/demos/b ... converter/
no so friendly playground (only potrace implementation) https://cancerberosgx.github.io/demos/s ... layground/#
If you play a little bit, for logos/drawing it works nice (and if you only need monochrome output then potrace implementation is almost perfect).
However if you want to "vectorize" photos the story is different. You can archieve almost perfect replicas, but the svg will have enourmous anount of shapes without any semantics and for most vector graphic use cases this is unuseful (imagine a plotting machine trying to cut/plot).
Also I recently discovered "geometrize/primitive" technologies (https://www.geometrize.co.uk/, https://github.com/fogleman/primitive) and made a port to JavaScript node.js browser API and CLI https://www.npmjs.com/package/geometrizejs to easily test it. Although this technology was not designed for this (mostly to create art/animations/effects) I realized that it's also capable of trace an image.
Finally I'm using svgo (svg optimizer in node.js and browser) which is capable of simplify any svg to a single or few paths. This seems interesting to combine with ImageMagick but this time as a rasterizer tool and compare with other similar technologies. BTW A fwe days ago I started working on a Node.js and browser API and CLI for ImageMagick utilities command line tools here https://www.npmjs.com/package/magica (it works fine, although slow compared to the real thing, same api for desktop and browser)
Since now I have all these supported in the same language and platforms one crazy objective would be to build (really don't know how) something that convolves a bitmap - edge detection and somehow find out the simpler paths to draw its main objects. I think I have a formal definition of these "main objects" but my math and expertise in areas like machine learning (that could probably be helpful in this) are very poor.
Do you know anybody worked on something like that bitmap->edges->"shapes"->vectors ?. or mixing imagemagick data extraction commands with machine learning to detect / separate / classigicate objects ? or some paper regarding important image properties to consider in this regard . The objective would be to generate arbitrary-simple vectors representing "shapes" and edges from arbitrary bitmap. The definition of these "objects", to start, could be something like clusters of similar color pixels... well I would really appreciate any tip or link on any similar, thanks. I didn't see any technology approaching the problem like this, but probably there are many.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Generating svg images using convert "command line"
cancerberosgx For converting shapes to vectors, you may like to look at IM Examples...
http://www.imagemagick.org/Usage//draw/#svg_output
Where I go though the process, using autotrace.
however SVG is not really suitable for 'drawing' real photos. I have now added a link from that area to your post as you provide some good links to various programs and techniques.
As for your goal. I myself can not help you a lot. Do you have an example of what you have achieved?
http://www.imagemagick.org/Usage//draw/#svg_output
Where I go though the process, using autotrace.
however SVG is not really suitable for 'drawing' real photos. I have now added a link from that area to your post as you provide some good links to various programs and techniques.
As for your goal. I myself can not help you a lot. Do you have an example of what you have achieved?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Generating svg images using convert "command line"
For some work I did vectorizing cartoons (with areas of flat colour), potrace and autotrace couldn't do what I needed, so I started from scratch. See Lines, points and curves.cancerberosgx wrote:Do you know anybody worked on something like that bitmap->edges->"shapes"->vectors ?
Photos aren't cartoons, but can be made so. See Flat-colour cartoons.
snibgo's IM pages: im.snibgo.com