mvg_spec.txt 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. Magick Vector Graphics
  2. MVG Overview • Drawing Primitives
  3. This specification defines the features and syntax for Magick Vector Graphics
  4. (MVG), a modularized language for describing two-dimensional vector and
  5. mixed vector/raster graphics in ImageMagick. You can use the language to draw
  6. from the command line, from an MVG file, from an SVG -- Scalable Vector Graphics
  7. file or from one of the ImageMagick program interfaces. Use this command,
  8. for example, to render an arc:
  9. magick -size 100x60 canvas:skyblue -fill white -stroke black \
  10. -draw "path 'M 30,40 A 30,20 20 0,0 70,20 A 30,20 20 1,0 30,40 Z '" \
  11. arc.png
  12. and here is the result:
  13. arc
  14. When the drawing gets sufficiently complex, we recommend you assemble the
  15. graphic primitives into a MVG file. For our example, we use piechart.mvg:
  16. push graphic-context
  17. viewbox 0 0 624 369
  18. affine 0.283636 0 0 0.283846 -0 -0
  19. push graphic-context
  20. push graphic-context
  21. fill 'darkslateblue'
  22. stroke 'blue'
  23. stroke-width 1
  24. rectangle 1,1 2199,1299
  25. pop graphic-context
  26. push graphic-context
  27. font-size 40
  28. fill 'white'
  29. stroke-width 1
  30. text 600,1100 'Average: 20.0'
  31. pop graphic-context
  32. push graphic-context
  33. fill 'red'
  34. stroke 'black'
  35. stroke-width 5
  36. path 'M700.0,600.0 L340.0,600.0 A360.0,360.0 0 0,1 408.1452123287954,389.2376150414973 z'
  37. pop graphic-context
  38. push graphic-context
  39. font-size 40
  40. fill 'white'
  41. stroke-width 1
  42. text 1400,140 'MagickWand for PHP'
  43. pop graphic-context
  44. push graphic-context
  45. font-size 30
  46. fill 'white'
  47. stroke-width 1
  48. text 1800,140 '(10.0%)'
  49. pop graphic-context
  50. push graphic-context
  51. fill 'red'
  52. stroke 'black'
  53. stroke-width 4
  54. rectangle 1330,100 1370,140
  55. pop graphic-context
  56. push graphic-context
  57. fill 'yellow'
  58. stroke 'black'
  59. stroke-width 5
  60. path 'M700.0,600.0 L408.1452123287954,389.2376150414973 A360.0,360.0 0 0,1 976.5894480359858,369.56936567559273 z'
  61. pop graphic-context
  62. push graphic-context
  63. font-size 40
  64. fill 'white'
  65. stroke-width 1
  66. text 1400,220 'MagickCore'
  67. pop graphic-context
  68. push graphic-context
  69. font-size 30
  70. fill 'white'
  71. stroke-width 1
  72. text 1800,220 '(29.0%)'
  73. pop graphic-context
  74. push graphic-context
  75. fill 'yellow'
  76. stroke 'black'
  77. stroke-width 4
  78. rectangle 1330,180 1370,220
  79. pop graphic-context
  80. push graphic-context
  81. fill 'fuchsia'
  82. stroke 'black'
  83. stroke-width 5
  84. path 'M700.0,600.0 L976.5894480359858,369.56936567559273 A360.0,360.0 0 0,1 964.2680466142854,844.4634932636567 z'
  85. pop graphic-context
  86. push graphic-context
  87. font-size 40
  88. fill 'white'
  89. stroke-width 1
  90. text 1400,300 'MagickWand'
  91. pop graphic-context
  92. push graphic-context
  93. font-size 30
  94. fill 'white'
  95. stroke-width 1
  96. text 1800,300 '(22.9%)'
  97. pop graphic-context
  98. push graphic-context
  99. fill 'fuchsia'
  100. stroke 'black'
  101. stroke-width 4
  102. rectangle 1330,260 1370,300
  103. pop graphic-context
  104. push graphic-context
  105. fill 'blue'
  106. stroke 'black'
  107. stroke-width 5
  108. path 'M700.0,600.0 L964.2680466142854,844.4634932636567 A360.0,360.0 0 0,1 757.853099990584,955.3210081341651 z'
  109. pop graphic-context
  110. push graphic-context
  111. font-size 40
  112. fill 'white'
  113. stroke-width 1
  114. text 1400,380 'JMagick'
  115. pop graphic-context
  116. push graphic-context
  117. font-size 30
  118. fill 'white'
  119. stroke-width 1
  120. text 1800,380 '(10.6%)'
  121. pop graphic-context
  122. push graphic-context
  123. fill 'blue'
  124. stroke 'black'
  125. stroke-width 4
  126. rectangle 1330,340 1370,380
  127. pop graphic-context
  128. push graphic-context
  129. fill 'lime'
  130. stroke 'black'
  131. stroke-width 5
  132. path 'M700.0,600.0 L757.853099990584,955.3210081341651 A360.0,360.0 0 0,1 340.0,600.0 z'
  133. pop graphic-context
  134. push graphic-context
  135. font-size 40
  136. fill 'white'
  137. stroke-width 1
  138. text 1400,460 'Magick++'
  139. pop graphic-context
  140. push graphic-context
  141. font-size 30
  142. fill 'white'
  143. stroke-width 1
  144. text 1800,460 '(27.5%)'
  145. pop graphic-context
  146. push graphic-context
  147. fill 'lime'
  148. stroke 'black'
  149. stroke-width 4
  150. rectangle 1330,420 1370,460
  151. pop graphic-context
  152. push graphic-context
  153. font-size 100
  154. fill 'white'
  155. stroke-width 1
  156. text 100,150 'ImageMagick'
  157. pop graphic-context
  158. push graphic-context
  159. fill 'none'
  160. stroke 'black'
  161. stroke-width 5
  162. circle 700,600 700,960
  163. pop graphic-context
  164. pop graphic-context
  165. pop graphic-context
  166. to render a pie chart with this command:
  167. magick mvg:piechart.mvg piechart.png
  168. which produces this rendering:
  169. piechart
  170. However, in general, MVG is sufficiently difficult to work with that you
  171. probably want to use a program to generate your graphics in the SVG format.
  172. ImageMagick automagically converts SVG to MVG and renders your image,
  173. for example, we render piechart.svg with this command:
  174. magick mvg:piechart.svg piechart.jpg
  175. to produce the same pie chart we created with the MVG language.
  176. MVG Overview
  177. MVG ignores all white-space between commands.
  178. This allows multiple MVG commands per line.
  179. It is common convention to terminate each MVG command with a newline to make
  180. MVG easier to edit and read. This syntax description uses indentation in
  181. MVG sequences to aid with understanding. Indentation is supported but is not
  182. required.
  183. Metafile wrapper syntax (to support stand-alone MVG files):
  184. push graphic-context
  185. viewbox 0 0 width height
  186. [ any other MVG commands ]
  187. pop graphic-context
  188. Pattern syntax (saving and restoring context):
  189. push pattern id x,y width,height
  190. push graphic-context
  191. [ drawing commands ]
  192. pop graphic-context
  193. pop pattern
  194. an example is (%s is a identifier string):
  195. push defs
  196. push pattern %s 10,10 20,20
  197. push graphic-context
  198. fill red
  199. rectangle 5,5 15,15
  200. pop graphic-context
  201. push graphic-context
  202. fill green
  203. rectangle 10,10 20,20
  204. pop graphic-context
  205. pop pattern
  206. pop defs
  207. For image tiling use:
  208. push pattern id x,y width,height
  209. image Copy ...
  210. pop pattern
  211. Note you can use the pattern for either the fill or stroke like:
  212. stroke url(#%s)
  213. or
  214. fill url(#%s)
  215. The clip path defines a clipping area, where only the contained area to be
  216. drawn upon. Areas outside of the clipping areare masked.
  217. push defs
  218. push clip-path "myClipPath"
  219. push graphic-context
  220. rectangle 10,10 20,20
  221. pop graphic-context
  222. pop clip-path
  223. pop defs
  224. clip-path url(#myClipPath)
  225. Drawing Primitives
  226. Here is a complete description of the MVG drawing primitives:
  227. Primitive Description
  228. affine sx,rx,ry,sy,tx,ty
  229. arc x0,y0 x1,y1 a0,a1
  230. bezier x0,y0 ... xn,yn Bezier (spline) requires three or more x,y coordinates
  231. to define its shape. The first and last points are the knots
  232. (preserved coordinates) and any intermediate coordinates are the control points.
  233. If two control points are specified, the line between each end knot and its
  234. sequentially respective control point determines the tangent direction of the
  235. curve at that end. If one control point is specified, the lines from the end
  236. knots to the one control point determines the tangent directions of the curve
  237. at each end. If more than two control points are specified, then the
  238. additional control points act in combination to determine the intermediate
  239. shape of the curve. In order to draw complex curves, it is highly recommended
  240. either to use the Path primitive or to draw multiple four-point bezier segments
  241. with the start and end knots of each successive segment repeated.
  242. border-color color
  243. circle originx,originy perimeterx,perimetery
  244. clip-path url(name)
  245. clip-rule rule Choose from these rule types:
  246. evenodd
  247. nonzero
  248. clip-units units Choose from these unit types:
  249. userSpace
  250. userSpaceOnUse
  251. objectBoundingBox
  252. color x,y method Choose from these method types:
  253. point
  254. replace
  255. floodfill
  256. filltoborder
  257. reset
  258. compliance type Choose from these compliance types: MVG or SVG
  259. decorate type Choose from these types of decorations:
  260. none
  261. line-through
  262. overline
  263. underline
  264. ellipse centerx,centery radiusx,radiusy arcstart,arcstop
  265. fill color Choose from any of these colors.
  266. fill-opacity opacity The opacity ranges from 0.0 (fully transparent) to 1.0
  267. (fully opaque) or as a percentage (e.g. 50%).
  268. fill-rule rule Choose from these rule types:
  269. evenodd
  270. nonzero
  271. font name
  272. font-family family
  273. font-size point-size
  274. font-stretch type Choose from these stretch types:
  275. all
  276. normal
  277. ultra-condensed
  278. extra-condensed
  279. condensed
  280. semi-condensed
  281. semi-expanded
  282. expanded
  283. extra-expanded
  284. ultra-expanded
  285. font-style style Choose from these styles:
  286. all
  287. normal
  288. italic
  289. oblique
  290. font-weight weight Choose from these weights:
  291. all
  292. normal
  293. bold
  294. 100
  295. 200
  296. 300
  297. 400
  298. 500
  299. 600
  300. 700
  301. 800
  302. 900
  303. gradient-units units Choose from these units:
  304. userSpace
  305. userSpaceOnUse
  306. objectBoundingBox
  307. gravity type Choose from these gravity types:
  308. NorthWest
  309. North
  310. NorthEast
  311. West
  312. Center
  313. East
  314. SouthWest
  315. South
  316. SouthEast
  317. image compose x,y width,height 'filename' Choose from these compose operations:
  318. Method Description
  319. clear Both the color and the alpha of the destination are cleared. Neither the source nor the destination are used as input.
  320. src The source is copied to the destination. The destination is not used as input.
  321. dst The destination is left untouched.
  322. src-over The source is composited over the destination.
  323. dst-over The destination is composited over the source and the result replaces the destination.
  324. src-in The part of the source lying inside of the destination replaces the destination.
  325. dst-in The part of the destination lying inside of the source replaces the destination.
  326. src-out The part of the source lying outside of the destination replaces the destination.
  327. dst-out The part of the destination lying outside of the source replaces the destination.
  328. src-atop The part of the source lying inside of the destination is composited onto the destination.
  329. dst-atop The part of the destination lying inside of the source is composited over the source and replaces the destination.
  330. multiply The source is multiplied by the destination and replaces the destination. The resultant color is always at least as dark as either of the two constituent colors. Multiplying any color with black produces black. Multiplying any color with white leaves the original color unchanged.
  331. screen The source and destination are complemented and then multiplied and then replace the destination. The resultant color is always at least as light as either of the two constituent colors. Screening any color with white produces white. Screening any color with black leaves the original color unchanged.
  332. overlay Multiplies or screens the colors, dependent on the destination color. Source colors overlay the destination whilst preserving its highlights and shadows. The destination color is not replaced, but is mixed with the source color to reflect the lightness or darkness of the destination.
  333. darken Selects the darker of the destination and source colors. The destination is replaced with the source when the source is darker, otherwise it is left unchanged.
  334. lighten Selects the lighter of the destination and source colors. The destination is replaced with the source when the source is lighter, otherwise it is left unchanged.
  335. linear-light Increase contrast slightly with an impact on the foreground's tonal values.
  336. color-dodge Brightens the destination color to reflect the source color. Painting with black produces no change.
  337. color-burn Darkens the destination color to reflect the source color. Painting with white produces no change.
  338. hard-light Multiplies or screens the colors, dependent on the source color value. If the source color is lighter than 0.5, the destination is lightened as if it were screened. If the source color is darker than 0.5, the destination is darkened, as if it were multiplied. The degree of lightening or darkening is proportional to the difference between the source color and 0.5. If it is equal to 0.5 the destination is unchanged. Painting with pure black or white produces black or white.
  339. soft-light Darkens or lightens the colors, dependent on the source color value. If the source color is lighter than 0.5, the destination is lightened. If the source color is darker than 0.5, the destination is darkened, as if it were burned in. The degree of darkening or lightening is proportional to the difference between the source color and 0.5. If it is equal to 0.5, the destination is unchanged. Painting with pure black or white produces a distinctly darker or lighter area, but does not result in pure black or white.
  340. plus The source is added to the destination and replaces the destination. This operator is useful for animating a dissolve between two images.
  341. add As per 'plus' but transparency data is treated as matte values. As such any transparent areas in either image remain transparent.
  342. minus Subtract the colors in the source image from the destination image. When transparency is involved, Opaque areas will be subtracted from any destination opaque areas.
  343. subtract Subtract the colors in the source image from the destination image. When transparency is involved transparent areas are subtracted, so only the opaque areas in the source remain opaque in the destination image.
  344. difference Subtracts the darker of the two constituent colors from the lighter. Painting with white inverts the destination color. Painting with black produces no change.
  345. exclusion Produces an effect similar to that of 'difference', but appears as lower contrast. Painting with white inverts the destination color. Painting with black produces no change.
  346. xor The part of the source that lies outside of the destination is combined with the part of the destination that lies outside of the source.
  347. copy-* Copy the specified channel in the source image to the same channel in the destination image. If the channel specified in the source image does not exist, (which can only happen for methods, 'copy-opacity' or 'copy-black') then it is assumed that the source image is a special grayscale channel image of the values to be copied.
  348. change-mask Replace any destination pixel that is the similar to the source images pixel (as defined by the current -fuzz factor), with transparency.
  349. interline-spacing pixels
  350. interword-spacing pixels
  351. kerning pixels
  352. line x,y x1,y1
  353. matte x,y method Choose from these methods:
  354. point
  355. replace
  356. floodfill
  357. filltoborder
  358. reset
  359. offset offset
  360. opacity opacity Use percent (e.g. 50%).
  361. path path
  362. point x,y
  363. polygon x,y x1,y1, ..., xn,yn
  364. polyline x,y x1,y1, ..., xn,yn
  365. pop clip-path
  366. pop defs
  367. pop gradient
  368. pop graphic-context
  369. pop pattern
  370. push clip-path "name"
  371. push defs
  372. push gradient id linear x,y x1,y1
  373. push gradient id radial xc,cy xf,yf radius
  374. push graphic-context { "id" } the id is optional
  375. push pattern id radial x,y width,height
  376. rectangle x,y x1,y1
  377. rotate angle
  378. roundrectangle x,y x1,y1 width,height
  379. scale x,y
  380. skewX angle
  381. skewX angle
  382. stop-color color offset
  383. stroke color
  384. stroke-antialias 0 • 1
  385. stroke-dasharray none • numeric-list
  386. stroke-dashoffset offset
  387. stroke-linecap type Choose from these cap types:
  388. butt
  389. round
  390. square
  391. stroke-linejoin type Choose from these join types:
  392. bevel
  393. miter
  394. round
  395. stroke-miterlimit limit
  396. stroke-opacity opacity The opacity ranges from 0.0 (fully transparent) to 1.0 (fully opaque) or as a percentage (e.g. 50%).
  397. stroke-width width
  398. text "text"
  399. text-antialias 0 • 1
  400. text-undercolor color
  401. translate x,y
  402. use "url(#id)"
  403. viewbox x,y x1,y1