top

Package svg generates SVG as defined by the Scalable Vector Graphics 1.1 Specification (<http://www.w3.org/TR/SVG11/>). Output goes to the specified io.Writer.

Supported SVG elements and functions

Shapes, lines, text

circle, ellipse, polygon, polyline, rect (including roundrects), line, text

Paths

general, arc, cubic and quadratic bezier paths,

Image and Gradients

image, linearGradient, radialGradient,

Transforms

translate, rotate, scale, skewX, skewY

Filter Effects

filter, feBlend, feColorMatrix, feColorMatrix, feComponentTransfer, feComposite, feConvolveMatrix, feDiffuseLighting,
feDisplacementMap, feDistantLight, feFlood, feGaussianBlur, feImage, feMerge, feMorphology, feOffset, fePointLight,
feSpecularLighting, feSpotLight,feTile, feTurbulence

Metadata elements

desc, defs, g (style, transform, id), mask, marker, pattern, title, (a)ddress, link, script, use

Usage: (assuming GOPATH is set)

go get github.com/ajstarks/svgo
go install github.com/ajstarks/svgo/...

You can use godoc to browse the documentation from the command line:

$ godoc github.com/ajstarks/svgo

a minimal program, to generate SVG to standard output.

package main

import (
	"github.com/ajstarks/svgo"
	"os"
)

func main() {
	width := 500
	height := 500
	canvas := svg.New(os.Stdout)
	canvas.Start(width, height)
	canvas.Circle(width/2, height/2, 100)
	canvas.Text(width/2, height/2, "Hello, SVG", "text-anchor:middle;font-size:30px;fill:white")
	canvas.End()
}

Drawing in a web server: (http://localhost:2003/circle)

package main

import (
	"log"
	"github.com/ajstarks/svgo"
	"net/http"
)

func main() {
	http.Handle("/circle", http.HandlerFunc(circle))
	err := http.ListenAndServe(":2003", nil)
	if err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}

func circle(w http.ResponseWriter, req *http.Request) {
  w.Header().Set("Content-Type", "image/svg+xml")
  s := svg.New(w)
  s.Start(500, 500)
  s.Circle(250, 250, 125, "fill:none;stroke:black")
  s.End()
}

Functions and types

Many functions use x, y to specify an object's location, and w, h to specify the object's width and height. Where applicable, a final optional argument specifies the style to be applied to the object. The style strings follow the SVG standard; name:value pairs delimited by semicolons, or a series of name="value" pairs. For example: `"fill:none; opacity:0.3"` or `fill="none" opacity="0.3"` (see: <http://www.w3.org/TR/SVG11/styling.html>)

The SVG type:

	type SVG struct {
        Writer   io.Writer
	}

Most operations are methods on this type, specifying the destination io.Writer.

The Offcolor type:

type Offcolor struct {
	Offset  uint8
	Color   string
	Opacity float64
}

is used to specify the offset, color, and opacity of stop colors in linear and radial gradients

The Filterspec type:

type Filterspec struct {
	In string
	In2 string
	Result string
}

is used to specify inputs and results for filter effects Package svg provides an API for generating Scalable Vector Graphics (SVG)

Imported by 415 package(s) ΒΆ

  1. bitbucket.org/hakanmalm/plot/vg/vgsvg
  2. bosun.org/cmd/bosun/sched
  3. bosun.org/cmd/bosun/web
  4. code.cloudfoundry.org/auction/simulation/visualization
  5. code.google.com/p/plotinum/vg/vgsvg
  6. github.com/Archs/chart/example
  7. github.com/Archs/chart/svgg
  8. github.com/Comdex/chart/example
  9. github.com/Comdex/chart/svgg
  10. github.com/Elucidation/go-supreme-pancake
  11. github.com/I82Much/BrickMosaic
  12. github.com/IntelliQru/go-svg-diagram
  13. github.com/IronGopher/gram
  14. github.com/JessonChan/go-chart/example
  15. github.com/JessonChan/go-chart/svgg
  16. github.com/Kunde21/plot/vg/vgsvg
  17. github.com/MattSPalmer/calligrapher
  18. github.com/MattSPalmer/svgraphs
  19. github.com/NerdGGuy/BulletGraphGo
  20. github.com/NerdGGuy/svgo/android
  21. github.com/NerdGGuy/svgo/bubtrail
  22. github.com/NerdGGuy/svgo/bulletgraph
  23. github.com/NerdGGuy/svgo/codepic
  24. github.com/NerdGGuy/svgo/colortab
  25. github.com/NerdGGuy/svgo/compx
  26. github.com/NerdGGuy/svgo/f50
  27. github.com/NerdGGuy/svgo/fe
  28. github.com/NerdGGuy/svgo/flower
  29. github.com/NerdGGuy/svgo/fontcompare
  30. github.com/NerdGGuy/svgo/funnel
  31. github.com/NerdGGuy/svgo/gradient
  32. github.com/NerdGGuy/svgo/html5logo
  33. github.com/NerdGGuy/svgo/imfade
  34. github.com/NerdGGuy/svgo/lewitt
  35. github.com/NerdGGuy/svgo/ltr
  36. github.com/NerdGGuy/svgo/paths
  37. github.com/NerdGGuy/svgo/planets
  38. github.com/NerdGGuy/svgo/pmap
  39. github.com/NerdGGuy/svgo/randcomp
  40. github.com/NerdGGuy/svgo/richter
  41. github.com/NerdGGuy/svgo/rl
  42. github.com/NerdGGuy/svgo/skewabc
  43. github.com/NerdGGuy/svgo/stockproduct
  44. github.com/NerdGGuy/svgo/svgdef
  45. github.com/NerdGGuy/svgo/svgopher
  46. github.com/NerdGGuy/svgo/svgplot
  47. github.com/NerdGGuy/svgo/svgrid
  48. github.com/NerdGGuy/svgo/tsg
  49. github.com/NerdGGuy/svgo/tumblrgrid
  50. github.com/NerdGGuy/svgo/turbulence
  51. github.com/NerdGGuy/svgo/vismem
  52. github.com/NerdGGuy/svgo/webfonts
  53. github.com/NerdGGuy/svgo/websvg
  54. github.com/Pythonidas/sigil/gen
  55. github.com/Requilence/GitFluence
  56. github.com/Robinbin/gostudy/concurrency
  57. github.com/SamuelRamond/xsro
  58. github.com/SivanMehta/mazes/generator
  59. github.com/Skarlso/goprojects/advent/day3
  60. github.com/aaronarduino/goqrsvg
  61. github.com/aclements/go-gg/gg
  62. github.com/aderjaan/moire/handlers
  63. github.com/ajstarks/chart/example
  64. github.com/ajstarks/chart/svgg
  65. github.com/ajstarks/deck/cmd/codepicdeck/code
  66. github.com/ajstarks/deck/cmd/svgdeck
  67. github.com/ajstarks/deck/examples
  68. github.com/ajstarks/go.vg/svgo
  69. github.com/ajstarks/graphicfarts
  70. github.com/ajstarks/kapok/visual
  71. github.com/ajstarks/svgo/barchart
  72. github.com/ajstarks/svgo/benchviz
  73. github.com/ajstarks/svgo/cube
  74. github.com/ajstarks/svgo/ltr
  75. github.com/ajstarks/svgo/pattern
  76. github.com/ajstarks/svgo/picserv
  77. github.com/ajstarks/svgo/rpd
  78. github.com/ajstarks/svgo/rr
  79. github.com/ajstarks/svgo/shotchart
  80. github.com/ajstarks/svgo/structlayout-svg
  81. github.com/akonneker/aruco_svg
  82. github.com/alimoeeny/chart/example
  83. github.com/alimoeeny/chart/svgg
  84. github.com/amitkgupta/auction/simulation/visualization
  85. github.com/andradeandrey/chart/example
  86. github.com/andradeandrey/chart/svgg
  87. github.com/atomaths/braille-printer/src
  88. github.com/axw/go-jupyter/example
  89. github.com/barnjamin/randomforest
  90. github.com/billhathaway/pingPongStatus
  91. github.com/breml/mygoplayground/svg
  92. github.com/bulletind/moire/handlers
  93. github.com/c4e8ece0/gcse/server
  94. github.com/campoy/svg-badge/badge
  95. github.com/ceftb/xir/tools/viz
  96. github.com/chrislusf/gleam/distributed/master/ui
  97. github.com/chrislusf/gleamold/distributed/master/ui
  98. github.com/cinnabardk/svg
  99. github.com/cloudfoundry-incubator/auction/simulation/visualization
  100. github.com/cloudfoundry/auction/simulation/visualization
  101. github.com/codahale/graphicfarts
  102. github.com/connor4312/dfa
  103. github.com/countcb/svgo/barchart
  104. github.com/countcb/svgo/benchviz
  105. github.com/countcb/svgo/cube
  106. github.com/countcb/svgo/ltr
  107. github.com/countcb/svgo/pattern
  108. github.com/countcb/svgo/picserv
  109. github.com/countcb/svgo/rpd
  110. github.com/countcb/svgo/rr
  111. github.com/countcb/svgo/shotchart
  112. github.com/countcb/svgo/structlayout-svg
  113. github.com/courtf/geom/carto
  114. github.com/coyotey/plot/vg/vgsvg
  115. github.com/cupcake/sigil/gen
  116. github.com/dalinaum/braille-printer/src
  117. github.com/davidamey/go-branching
  118. github.com/daviddengcn/gcse/server
  119. github.com/dchapes/svgo/barchart
  120. github.com/dchapes/svgo/benchviz
  121. github.com/dchapes/svgo/cube
  122. github.com/dchapes/svgo/ltr
  123. github.com/dchapes/svgo/pattern
  124. github.com/dchapes/svgo/picserv
  125. github.com/dchapes/svgo/rpd
  126. github.com/dchapes/svgo/rr
  127. github.com/dchapes/svgo/shotchart
  128. github.com/dchapes/svgo/structlayout-svg
  129. github.com/dddaisuke/chart/example
  130. github.com/dddaisuke/chart/svgg
  131. github.com/dixonwille/InitialAvatars
  132. github.com/droundy/abridge/abridge
  133. github.com/droundy/abridge/testing
  134. github.com/eaburns/plot/vg/vgsvg
  135. github.com/eaciit/svgo/barchart
  136. github.com/eaciit/svgo/benchviz
  137. github.com/eaciit/svgo/cube
  138. github.com/eaciit/svgo/ltr
  139. github.com/eaciit/svgo/pattern
  140. github.com/eaciit/svgo/picserv
  141. github.com/eaciit/svgo/rpd
  142. github.com/eaciit/svgo/rr
  143. github.com/eaciit/svgo/shotchart
  144. github.com/emicklei/talks/2013/spirograph
  145. github.com/emicklei/zenna/bisos
  146. github.com/emicklei/zenna/mozara
  147. github.com/emicklei/zenna/notez
  148. github.com/emicklei/zenna/svgf
  149. github.com/emicklei/zenna/talks
  150. github.com/emicklei/zenna/trapezia
  151. github.com/etherealmachine/hivemind/src
  152. github.com/fabiolb/logo
  153. github.com/fedesog/svgo/barchart
  154. github.com/fedesog/svgo/benchviz
  155. github.com/fedesog/svgo/rr
  156. github.com/felixanya/chart/example
  157. github.com/felixanya/chart/svgg
  158. github.com/ffel/prd/prdsymb
  159. github.com/foobaz/geom/carto
  160. github.com/frankban/jujusvg
  161. github.com/fredericlemoine/gotree/draw
  162. github.com/go-spatial/tegola/draw/svg
  163. github.com/go-spatial/tegola/maths/clip/internal/draw
  164. github.com/go-spatial/tegola/maths/makevalid/plyg
  165. github.com/godsic/wpi2svg
  166. github.com/gonum/plot/vg/vgsvg
  167. github.com/gonuts/go-chart/example
  168. github.com/gonuts/go-chart/svgg
  169. github.com/gophergala2016/chartit
  170. github.com/gophergala2016/rdbanalyzer
  171. github.com/gostudent/aurora
  172. github.com/grafov/chart/example
  173. github.com/grafov/chart/svgg
  174. github.com/guesslin/chartit
  175. github.com/haldean/chart/example
  176. github.com/haldean/chart/svgg
  177. github.com/hamdouni/svgo/barchart
  178. github.com/hamdouni/svgo/benchviz
  179. github.com/hamdouni/svgo/cube
  180. github.com/hamdouni/svgo/ltr
  181. github.com/hamdouni/svgo/pattern
  182. github.com/hamdouni/svgo/picserv
  183. github.com/hamdouni/svgo/rpd
  184. github.com/hamdouni/svgo/rr
  185. github.com/hamdouni/svgo/shotchart
  186. github.com/helmi03/golang-stuff/github.com/ajstarks/svgo/barchart
  187. github.com/helmi03/golang-stuff/github.com/ajstarks/svgo/benchviz
  188. github.com/helmi03/golang-stuff/github.com/ajstarks/svgo/rr
  189. github.com/helmi03/golang-stuff/github.com/vdobler/chart/example
  190. github.com/helmi03/golang-stuff/github.com/vdobler/chart/svgg
  191. github.com/henryscala/misc_learn/src
  192. github.com/hermansc/kmeans
  193. github.com/high5/picsv
  194. github.com/highway900/levelgen
  195. github.com/huguesalary/svgo/barchart
  196. github.com/huguesalary/svgo/benchviz
  197. github.com/huguesalary/svgo/cube
  198. github.com/huguesalary/svgo/ltr
  199. github.com/huguesalary/svgo/pattern
  200. github.com/huguesalary/svgo/picserv
  201. github.com/huguesalary/svgo/rpd
  202. github.com/huguesalary/svgo/rr
  203. github.com/ironarachne/heraldry
  204. github.com/jackielii/go-plotinum/vg/vgsvg
  205. github.com/jelmersnoeck/svgo/barchart
  206. github.com/jelmersnoeck/svgo/benchviz
  207. github.com/jelmersnoeck/svgo/cube
  208. github.com/jelmersnoeck/svgo/ltr
  209. github.com/jelmersnoeck/svgo/pattern
  210. github.com/jelmersnoeck/svgo/picserv
  211. github.com/jelmersnoeck/svgo/rpd
  212. github.com/jelmersnoeck/svgo/rr
  213. github.com/jelmersnoeck/svgo/shotchart
  214. github.com/jmank88/ca/lib
  215. github.com/jmank88/svgo/barchart
  216. github.com/jmank88/svgo/benchviz
  217. github.com/jmank88/svgo/cube
  218. github.com/jmank88/svgo/ltr
  219. github.com/jmank88/svgo/pattern
  220. github.com/jmank88/svgo/picserv
  221. github.com/jmank88/svgo/rpd
  222. github.com/jmank88/svgo/rr
  223. github.com/jnb666/gogp/util
  224. github.com/jonahs99/contour
  225. github.com/jonhanks/svgfractal
  226. github.com/juju/jujusvg
  227. github.com/justincinmd/plot/vg/vgsvg
  228. github.com/kenrick/split-badge
  229. github.com/kevinlebrun/dots
  230. github.com/kljensen/borkedbuild
  231. github.com/krasin/abc-cube
  232. github.com/krasin/abc-cube/folding
  233. github.com/lanastasov/gcse/server
  234. github.com/layer-x/pluggable-auction/simulation/visualization
  235. github.com/liudch/chart/example
  236. github.com/liudch/chart/svgg
  237. github.com/lmika/goseq/seqdiagram/graphbox
  238. github.com/loganjspears/chessimg
  239. github.com/lucumt/svgo/barchart
  240. github.com/lucumt/svgo/benchviz
  241. github.com/lucumt/svgo/cube
  242. github.com/lucumt/svgo/ltr
  243. github.com/lucumt/svgo/pattern
  244. github.com/lucumt/svgo/picserv
  245. github.com/lucumt/svgo/rpd
  246. github.com/lucumt/svgo/rr
  247. github.com/lucumt/svgo/shotchart
  248. github.com/lucumt/svgo/structlayout-svg
  249. github.com/luosangnanka/gcse/server
  250. github.com/makyo/jujusvg
  251. github.com/mewbak/gcse/server
  252. github.com/mhilton/juju-jujusvg
  253. github.com/mhilton/jujusvg
  254. github.com/mhutter/gcse/server
  255. github.com/milliyang/chart/example
  256. github.com/milliyang/chart/svgg
  257. github.com/milliyang/golang-stuff/github.com/ajstarks/svgo/barchart
  258. github.com/milliyang/golang-stuff/github.com/ajstarks/svgo/benchviz
  259. github.com/milliyang/golang-stuff/github.com/ajstarks/svgo/rr
  260. github.com/milliyang/golang-stuff/github.com/vdobler/chart/example
  261. github.com/milliyang/golang-stuff/github.com/vdobler/chart/svgg
  262. github.com/milliyang/svgo/barchart
  263. github.com/milliyang/svgo/benchviz
  264. github.com/milliyang/svgo/ltr
  265. github.com/milliyang/svgo/pattern
  266. github.com/milliyang/svgo/rpd
  267. github.com/milliyang/svgo/rr
  268. github.com/minotar/imgd
  269. github.com/mkouhei/golang-ajstarks-svgo-debian/barchart
  270. github.com/mkouhei/golang-ajstarks-svgo-debian/benchviz
  271. github.com/mkouhei/golang-ajstarks-svgo-debian/rr
  272. github.com/mooncaker816/go-calendar
  273. github.com/mrsinham/map
  274. github.com/nfdesign/maping/gensvg
  275. github.com/nilbot/chart/example
  276. github.com/nilbot/chart/svgg
  277. github.com/nobonobo/vecty-chatapp/app/components
  278. github.com/nobonobo/vecty-sample/app/components
  279. github.com/nochso/colourl/palette
  280. github.com/notnil/chessimg
  281. github.com/nuqz/plot/vg/vgsvg
  282. github.com/omni360/golang-svgo-debian/barchart
  283. github.com/omni360/golang-svgo-debian/benchviz
  284. github.com/omni360/golang-svgo-debian/rr
  285. github.com/pavel-paulau/perfdb
  286. github.com/philip1986/game_of_life
  287. github.com/postfix/svgo/barchart
  288. github.com/postfix/svgo/benchviz
  289. github.com/postfix/svgo/rr
  290. github.com/pwaller/go-chart/example
  291. github.com/pwaller/go-chart/svgg
  292. github.com/quchunguang/projecteuler
  293. github.com/randall77/svgo/barchart
  294. github.com/randall77/svgo/benchviz
  295. github.com/randall77/svgo/cube
  296. github.com/randall77/svgo/ltr
  297. github.com/randall77/svgo/pattern
  298. github.com/randall77/svgo/picserv
  299. github.com/randall77/svgo/rpd
  300. github.com/randall77/svgo/rr
  301. github.com/randall77/svgo/shotchart
  302. github.com/requilence/GitFluence
  303. github.com/rqme/neat/visualizer
  304. github.com/rqme/neat/x/examples/boxes
  305. github.com/rqme/neat/x/examples/maze
  306. github.com/rzh/chart/example
  307. github.com/rzh/chart/svgg
  308. github.com/rzh/svgo/barchart
  309. github.com/rzh/svgo/benchviz
  310. github.com/rzh/svgo/pattern
  311. github.com/rzh/svgo/rr
  312. github.com/saljam/tessellations
  313. github.com/samertm/githubstreaks
  314. github.com/samuelramond/xsro
  315. github.com/skelterjohn/go.vg/svgo
  316. github.com/skiesel/plot/vg/vgsvg
  317. github.com/sksullivan/plot/vg/vgsvg
  318. github.com/soniakeys/bio/logo
  319. github.com/stanim/chart/example
  320. github.com/stanim/chart/svgg
  321. github.com/stanim/svgo/barchart
  322. github.com/stanim/svgo/benchviz
  323. github.com/stanim/svgo/cube
  324. github.com/stanim/svgo/ltr
  325. github.com/stanim/svgo/pattern
  326. github.com/stanim/svgo/picserv
  327. github.com/stanim/svgo/rpd
  328. github.com/stanim/svgo/rr
  329. github.com/stephen-soltesz/chart/example
  330. github.com/stephen-soltesz/chart/svgg
  331. github.com/stephen-soltesz/go/plotter
  332. github.com/suapapa/braille-printer/src
  333. github.com/suapapa/go_braille/svg
  334. github.com/subosito/gcse/server
  335. github.com/swill/svgo/barchart
  336. github.com/swill/svgo/benchviz
  337. github.com/swill/svgo/cube
  338. github.com/swill/svgo/ltr
  339. github.com/swill/svgo/pattern
  340. github.com/swill/svgo/picserv
  341. github.com/swill/svgo/rpd
  342. github.com/swill/svgo/rr
  343. github.com/tadvi/vichart/vichart
  344. github.com/tadvi/vichart/webcharts
  345. github.com/taironas/tinygraphs/draw/isogrids
  346. github.com/taironas/tinygraphs/draw/spaceinvaders
  347. github.com/taironas/tinygraphs/draw/squares
  348. github.com/teknico/deck/examples
  349. github.com/terranodo/tegola/draw/svg
  350. github.com/terranodo/tegola/maths/clip/internal/draw
  351. github.com/terranodo/tegola/maths/makevalid/plyg
  352. github.com/tleyden/neurgo
  353. github.com/tomarus/svgo/barchart
  354. github.com/tomarus/svgo/benchviz
  355. github.com/tomarus/svgo/cube
  356. github.com/tomarus/svgo/ltr
  357. github.com/tomarus/svgo/pattern
  358. github.com/tomarus/svgo/picserv
  359. github.com/tomarus/svgo/rpd
  360. github.com/tomarus/svgo/rr
  361. github.com/tomarus/svgo/shotchart
  362. github.com/tomarus/svgo/structlayout-svg
  363. github.com/usiegj00/svgo/android
  364. github.com/usiegj00/svgo/bubtrail
  365. github.com/usiegj00/svgo/bulletgraph
  366. github.com/usiegj00/svgo/codepic
  367. github.com/usiegj00/svgo/colortab
  368. github.com/usiegj00/svgo/compx
  369. github.com/usiegj00/svgo/f50
  370. github.com/usiegj00/svgo/fe
  371. github.com/usiegj00/svgo/flower
  372. github.com/usiegj00/svgo/fontcompare
  373. github.com/usiegj00/svgo/funnel
  374. github.com/usiegj00/svgo/gradient
  375. github.com/usiegj00/svgo/html5logo
  376. github.com/usiegj00/svgo/imfade
  377. github.com/usiegj00/svgo/lewitt
  378. github.com/usiegj00/svgo/ltr
  379. github.com/usiegj00/svgo/paths
  380. github.com/usiegj00/svgo/planets
  381. github.com/usiegj00/svgo/pmap
  382. github.com/usiegj00/svgo/randcomp
  383. github.com/usiegj00/svgo/richter
  384. github.com/usiegj00/svgo/rl
  385. github.com/usiegj00/svgo/skewabc
  386. github.com/usiegj00/svgo/stockproduct
  387. github.com/usiegj00/svgo/svgdef
  388. github.com/usiegj00/svgo/svgopher
  389. github.com/usiegj00/svgo/svgplot
  390. github.com/usiegj00/svgo/svgrid
  391. github.com/usiegj00/svgo/tsg
  392. github.com/usiegj00/svgo/tumblrgrid
  393. github.com/usiegj00/svgo/turbulence
  394. github.com/usiegj00/svgo/vismem
  395. github.com/usiegj00/svgo/webfonts
  396. github.com/usiegj00/svgo/websvg
  397. github.com/vdobler/chart/example
  398. github.com/vdobler/chart/svgg
  399. github.com/vdobler/webtest
  400. github.com/vron/plotinum/vg/vgsvg
  401. github.com/wallyworld/jujusvg
  402. github.com/wantonsolutions/kmeans
  403. github.com/wdreeveii/CoilCalculator
  404. github.com/xladykiller/gcse/server
  405. github.com/xormplus/chart/example
  406. github.com/xormplus/chart/svgg
  407. github.com/yofu/st/stlib
  408. github.com/zhaihj/keygraph.go/graph
  409. github.com/zhuharev/stat/web
  410. github.com/zklapow/gpath/quadtree
  411. github.com/zyfdegh/digits2svg
  412. gopkg.in/juju/jujusvg.v1
  413. gopkg.in/juju/jujusvg.v2
  414. gopkg.in/nilbot/chart.v0/example
  415. gopkg.in/nilbot/chart.v0/svgg