How can I draw an SVG line from some points?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
haroldhawkey
Posts: 3
Joined: 2012-08-27T06:02:33-07:00
Authentication code: 67789

How can I draw an SVG line from some points?

Post by haroldhawkey »

Hello, I would like to draw a line. Seriously, just a line. From some points. Without any fill. And get a nice svg at the end. I tried this:

Code: Select all

convert -size 350x350 canvas:skyblue -fill none -stroke blue \
-draw "path 'M 200,140 300,150 300,140 40,300'" \ test.svg
But it fills it in black.

What am I doing wrong?
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: How can I draw an SVG line from some points?

Post by whugemann »

I believe this to be a bug in the SVG delegate. If you write a raster image, say PNG, instead, the result is just as expected. I think that ImageMagick is not that good at writing vector graphics; it's mostly a raster graphics program.
Wolfgang Hugemann
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How can I draw an SVG line from some points?

Post by fmw42 »

I know little about SVG, but have you tried using the RSVG delegate instead of the built in IM SVG. It is usually better.

Part of the problem may be that you have crossing lines but not a closed path.

Also you are creating a vector file from a raster engine. Perhaps you should build the SVG file from scratch and not try using IM -draw.

These are all guesses. Anthony is the expert on this.
haroldhawkey
Posts: 3
Joined: 2012-08-27T06:02:33-07:00
Authentication code: 67789

Re: How can I draw an SVG line from some points?

Post by haroldhawkey »

whugemann wrote: I think that ImageMagick is not that good at writing vector graphics; it's mostly a raster graphics program.
Oh Jeebuz....I wondered why all the tutorials seemed to love gif and png so much.
fmw42 wrote:Perhaps you should build the SVG file from scratch.
Yup, thats what I've been trying to work out how to do all day. Not for a single line of course...

Going quite well really, I made a 300 line bash script that churns out a very small image in a huge amount of time. Result!

Thanks for the informative replies dudes!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How can I draw an SVG line from some points?

Post by anthony »

DRAW does not use SVG delegates at all... That is only of rSVG files.

Draw draws what you specifial with draw.. That is it.

As for why it is failing. Stroke is the outside border Fill is the inside fill, and that defaults to black!!!

Set -fill and leave stroke off is that is not wanted.


WARNING: fill enlarges the fill area by 1/2 pixel. This is done to allow drawing of lines to work (or by default you never see any line drawn) but really it is wrong. It becomes a problem only when no stroke is used, and you want to 'join' adjacent polygonal areas.
See Draw Fill Bounds...
http://www.imagemagick.org/Usage/draw/#bounds

One solution is to have 'stoke' default to 'fill' when unset, and fill not 'enlarge' drawn areas. that way if you specific set stroke to 'none' areas will not become 'enlarged'. The problem is that at this time the stoke color can not be 'unset', or fall back to 'fill'.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
haroldhawkey
Posts: 3
Joined: 2012-08-27T06:02:33-07:00
Authentication code: 67789

Re: How can I draw an SVG line from some points?

Post by haroldhawkey »

Thanks for the info, I think that making the svg file with scripting actually saves me time instead of getting the points into imagemagick and then getting imagemagick to write the svg. Wrong tools for the job and all that sort of thing.

Right, I'm off to fry an egg with a laser, some petrol and a hammer...
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How can I draw an SVG line from some points?

Post by anthony »

Reminds me of the Jet powered beer cooler. -- cools a beer in 3 seconds, using gas expansion. The jet was to get rid of the expanded gas in a fun way. :-)

I have not looked to see if SVG has the same '1/2 pixel enlargement' that area fills in IM do.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply