go get github.com/ajstarks/svgo go install github.com/ajstarks/svgo/...
$ go doc github.com/ajstarks/svgo
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() }
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() }
$ svgplay 2014/06/25 22:05:28 ☠ ☠ ☠ Warning: this server allows a client connecting to 127.0.0.1:1999 to execute code on this computer ☠ ☠ ☠
http://localhost:1999/
http://localhost:1999/foo.go
-
SVGo paper from SVGOpen 2011 http://www.svgopen.org/2011/papers/34-SVGo_a_Go_Library_for_SVG_generation -
Programming Pictures with SVGo https://speakerdeck.com/u/ajstarks/p/programming-pictures-with-svgo -
SVGo Workshop https://speakerdeck.com/u/ajstarks/p/svgo-workshop
-
svg.go: Library -
newsvg: Coding template command -
svgdef: Creates a SVG representation of the API -
animate: Animation demo -
am: Animate motion demo -
amt: Animate transformation demo -
android: The Android logo -
bubtrail: Bubble trails -
bulletgraph: Bullet Graphs (via Stephen Few) -
colortab: Display SVG named colors with RGB values -
compx: Component diagrams -
flower: Random "flowers" -
fontcompare: Compare two fonts -
f50: Get 50 photos from Flickr based on a query -
fe: Filter effects -
funnel: Funnel from transparent circles -
gradient: Linear and radial gradients -
html5logo: HTML5 logo with draggable elements -
imfade: Show image fading -
lewitt: Version of Sol Lewitt's Wall Drawing 91 -
ltr: Layer Tennis Remixes -
marker: Test markers -
paths: Demonstrate SVG paths -
pattern: Test patterns -
planets: Show the scale of the Solar system -
pmap: Proportion maps -
randcomp: Compare random number generators -
richter: Gerhard Richter's 256 colors -
rl: Random lines (port of a Processing demo) -
skewabc: Skew ABC -
span: Text span -
stockproduct: Visualize product and stock prices -
svgopher: SVGo Mascot -
svgplay: SVGo sketching server -
svgplot: Plot data -
svgrid: Compose SVG files in a grid -
tsg: Twitter Search Grid -
tumblrgrid: Tumblr picture grid -
turbulence: Turbulence filter effect -
vismem: Visualize data from files -
webfonts: "Hello, World" with Google Web Fonts -
websvg: Generate SVG as a web server
type SVG struct { Writer io.Writer }
type Offcolor struct { Offset uint8 Color string Opacity float64 }
type Filterspec struct { In string In2 string Result string }
New(w io.Writer) *SVG
Start(w int, h int, attributes ...string)
Startview(w, h, minx, miny, vw, vh int)
Startunit(w int, h int, unit string, ns ...string)
Startpercent(w int, h int, ns ...string)
StartviewUnit(w, h int, unit string, minx, miny, vw, vh int)
End()
Script(scriptype string, data ...string)
Style(scriptype string, data ...string)
Group(s ... string)
Gstyle(s string)
Gid(s string)
Gtransform(s string)
Translate(x, y int)
Scale(n float64)
ScaleXY(x, y float64)
SkewX(a float64)
SkewY(a float64)
SkewXY(ax, ay float64)
Rotate(r float64)
TranslateRotate(x, y int, r float64)
RotateTranslate(x, y int, r float64)
Gend()
ClipPath(s ... string)
ClipEnd()
Def()
DefEnd()
Marker(id string, x, y, w, h int, s ...string)
MarkerEnd()
Mask(id string, x int, y int, w int, h int, s ...string)
MaskEnd()
Pattern(id string, x, y, width, height int, putype string, s ...string)
Desc(s string)
Title(s string)
Link(href string, title string)
LinkEnd()
Use(x int, y int, link string, s ...string)
Circle(x int, y int, r int, s ...string)
Ellipse(x int, y int, w int, h int, s ...string)
Polygon(x []int, y []int, s ...string)
Rect(x int, y int, w int, h int, s ...string)
CenterRect(x int, y int, w int, h int, s ...string)
Roundrect(x int, y int, w int, h int, rx int, ry int, s ...string)
Square(x int, y int, s int, style ...string)
Path(p string, s ...style)
Arc(sx int, sy int, ax int, ay int, r int, large bool, sweep bool, ex int, ey int, s ...string)
Bezier(sx int, sy int, cx int, cy int, px int, py int, ex int, ey int, s ...string)
Qbezier(sx int, sy int, cx int, cy int, ex int, ey int, tx int, ty int, s ...string)
Qbez(sx int, sy int, cx int, cy int, ex int, ey int, s...string)
Line(x1 int, y1 int, x2 int, y2 int, s ...string)
Polyline(x []int, y []int, s ...string)
Image(x int, y int, w int, h int, link string, s ...string)
Text(x int, y int, t string, s ...string)
Textspan(x int, y int, t string, s ...string)
Span(t string, s ...string)
TextEnd()
Textlines(x, y int, s []string, size, spacing int, fill, align string)
Textpath(t string, pathid string, s ...string)
RGB(r int, g int, b int) string
RGBA(r int, g int, b int, a float64) string
LinearGradient(id string, x1, y1, x2, y2 uint8, sc []Offcolor)
RadialGradient(id string, cx, cy, r, fx, fy uint8, sc []Offcolor)
Animate(link, attr string, from, to int, duration float64, repeat int, s ...string)
AnimateMotion(link, path string, duration float64, repeat int, s ...string)
AnimateTranslate(link string, fx, fy, tx, ty int, duration float64, repeat int, s ...string)
AnimateRotate(link string, fs, fc, fe, ts, tc, te int, duration float64, repeat int, s ...string)
AnimateScale(link string, from, to, duration float64, repeat int, s ...string)
AnimateSkewX(link string, from, to, duration float64, repeat int, s ...string)
AnimateSkewY(link string, from, to, duration float64, repeat int, s ...string)
Filter(id string, s ...string)
Fend()
FeBlend(fs Filterspec, mode string, s ...string)
FeColorMatrix(fs Filterspec, values [20]float64, s ...string)
FeColorMatrixHue(fs Filterspec, value float64, s ...string)
FeColorMatrixSaturate(fs Filterspec, value float64, s ...string)
FeColorMatrixLuminence(fs Filterspec, s ...string)
FeComponentTransfer()
FeCompEnd()
FeComposite(fs Filterspec, operator string, k1, k2, k3, k4 int, s ...string)
FeConvolveMatrix(fs Filterspec, matrix [9]int, s ...string)
FeDiffuseLighting(fs Filterspec, scale, constant float64, s ...string)
FeDiffEnd()
FeDisplacementMap(fs Filterspec, scale float64, xchannel, ychannel string, s ...string)
FeDistantLight(fs Filterspec, azimuth, elevation float64, s ...string)
FeFlood(fs Filterspec, color string, opacity float64, s ...string)
FeFuncLinear(channel string, slope, intercept float64)
FeFuncGamma(channel, amplitude, exponent, offset float64)
FeFuncTable(channel string, tv []float64)
FeFuncDiscrete(channel string, tv []float64)
FeGaussianBlur(fs Filterspec, stdx, stdy float64, s ...string)
FeImage(href string, result string, s ...string)
FeMerge(nodes []string, s ...string)
FeMorphology(fs Filterspec, operator string, xradius, yradius float64, s ...string)
FeOffset(fs Filterspec, dx, dy int, s ...string)
FePointLight(x, y, z float64, s ...string)
FeSpecularLighting(fs Filterspec, scale, constant float64, exponent int, color string, s ...string)
FeSpecEnd()
FeSpotLight(fs Filterspec, x, y, z, px, py, pz float64, s ...string)
FeTile(fs Filterspec, in string, s ...string)
FeTurbulence(fs Filterspec, ftype string, bfx, bfy float64, octaves int, seed int64, stitch bool, s ...string)
Blur(p float64)
Brightness(p float64)
Grayscale()
HueRotate(a float64)
Invert()
Saturate(p float64)
Sepia()
Grid(x int, y int, w int, h int, n int, s ...string)