[Introduction to Vector Graphics | MVG Overview | Drawing Primitives]
Introduction to Vector Graphics
This specification defines the features and syntax for Magick Vector Graphics (MVG), a modularized language for describing two-dimensional vector and mixed vector/raster graphics in ImageMagick. You can use the language to draw from the
command line, from an MVG file, from an SVG -- Scalable Vector Graphics file or from one of the ImageMagick program interfaces. Use this command, for example, to render an arc:
convert -size 100x60 xc:skyblue -fill white -stroke black \
-draw "path 'M 30,40 A 30,20 20 0,0 70,20 A 30,20 20 1,0 30,40 Z '" \
arc.png
and here is the results:
When the drawing gets sufficiently complex, we recommend you assemble the graphic primitives into a MVG file. For our example, we use piechart.mvg to render a pie chart with this command:
convert piechart.mvg piechart.png
which produces this rendering:
However, in general, MVG is sufficiently difficult to work with that you probably want to use a program to generate your graphics in the SVG format. ImageMagick automatically converts SVG to MVG and renders your image, for example, we render piechart.svg with this command:
convert piechart.svg piechart.jpg
to produce the same pie chart we created with the the MVG language.
Drawing is available from many of the ImageMagick program interfaces as well. ImageMagick converts the drawing API calls to MVG and renders it. Here is example code written in the MagickWand language:
(void) PushDrawingWand(draw_wand);
{
const PointInfo points[6] =
{
{ 180,504 },
{ 282.7,578.6 },
{ 243.5,699.4 },
{ 116.5,699.4 },
{ 77.26,578.6 },
{ 180,504 }
};
DrawSetStrokeAntialias(draw_wand,True);
DrawSetStrokeWidth(draw_wand,9);
DrawSetStrokeLineCap(draw_wand,RoundCap);
DrawSetStrokeLineJoin(draw_wand,RoundJoin);
(void) DrawSetStrokeDashArray(draw_wand,0,(const double *)NULL);
(void) PixelSetColor(color,"#4000c2");
DrawSetStrokeColor(draw_wand,color);
DrawSetFillRule(draw_wand,EvenOddRule);
(void) PixelSetColor(color,"#800000");
DrawSetFillColor(draw_wand,color);
DrawPolygon(draw_wand,6,points);
}
(void) PopDrawingWand(draw_wand);
MVG ignores all white-space between commands. This allows multiple MVG commands per line. It is common convention to terminate each MVG command with a new line to make MVG easier to edit and read. This syntax description uses indentation in MVG sequences to aid with understanding. Indentation is supported but is not required.
Metafile wrapper syntax (to support stand-alone MVG files):
push graphic-context
viewbox 0 0 width height
[ any other MVG commands ]
pop graphic-context
Pattern syntax (saving and restoring context):
push pattern id x,y width,height
push graphic-context
[ drawing commands ]
pop graphic-context
pop pattern
an example is (%s is a identifier string):
push defs
push pattern %s 10,10 20,20
push graphic-context
fill red
rectangle 5,5 15,15
pop graphic-context
push graphic-context
fill green
rectangle 10,10 20,20
pop graphic-context
pop pattern
pop defs
For image tiling use:
push pattern id x,y width,height
image Copy ...
pop pattern
Note you can use the pattern for either the fill or stroke like:
stroke url(#%s)
or
fill url(#%s)
The clip path defines a clipping area, where only the contained area to be drawn upon. Areas outside of the clipping area are masked.
push defs
push clip-path %s
push graphic-context
rectangle 10,10 20,20
pop graphic-context
pop clip-path
pop defs
clip-path url(#%s)
Here is a complete description of the MVG drawing primitives:
evenodd
nonzero
Choose from these unit types:
userSpace
userSpaceOnUse
objectBoundingBox
Choose from these method types:
point
replace
floodfill
filltoborder
reset
Choose from these types of decorations:
none
line-through
overline
underline
ellipse centerx,centery radiusx,radiusy arcstart,arcstop
Choose from any of these colors.
The opacity ranges from 0.0 (fully transparent) to 1.0 (fully opaque) or as a percentage (e.g. 50%).
Choose from these rule types:
evenodd
nonzero
Choose from these stretch types:
all
normal
ultra-condensed
extra-condensed
condensed
semi-condensed
semi-expanded
expanded
extra-expanded
ultra-expanded
Choose from these styles:
all
normal
italic
oblique
Choose from these weights:
all
normal
bold
100
200
300
400
500
600
700
800
900
Choose from these units:
userSpace
userSpaceOnUse
objectBoundingBox
Choose from these gravity types:
NorthWest
North
NorthEast
West
Center
East
SouthWest
South
SouthEast
image compose x,y width,height 'filename'
Choose from these compose operations:
Add
Atop
Bumpmap
Clear
CopyBlue
CopyGreen
CopyOpacity
CopyRed
Copy
Difference
In
Minus
Multiply
Out
Over
Plus
Subtract
Xor
Choose from these methods:
point
replace
floodfill
filltoborder
reset
Use percent (e.g. 50%).
polygon x,y x1,y1, ..., xn,yn
polyline x,y x1,y1, ..., xn,yn
push gradient id linear x,y x1,y1
push gradient id radial xc,cy xf,yf radius
push pattern id radial x,y width,height
roundrectangle x,y x1,y1 width,height
stroke-dasharray none | numeric-list
Choose from these cap types:
butt
round
square
Choose from these join types:
bevel
miter
round
The opacity ranges from 0.0 (fully transparent) to 1.0 (fully opaque) or as a percentage (e.g. 50%).
|