Skip to content

bernerdschaefer/svg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SVG

This is a library for building SVG images in ruby, using libxml-ruby.

Examples

Drawing a square

# examples/square/square.rb
canvas = SVG::Canvas.new 100, 100
canvas.rect x: 10, y: 10, width: 80, height: 80 do |square|
  square["fill"] = "#ccc"
end
canvas.save "square.svg"

Drawing a star

# Adapted from http://www.w3.org/TR/SVG/images/painting/fillrule-nonzero.svg

canvas = SVG::Canvas.new "12cm", "4cm"
canvas[:viewBox] = "0 0 1200 400"

canvas.g do |g|
  g["fill"] = "red"
  g.path do |path|
    path.move_to! 250, 75
    path.line_to! 323, 301
    path.line_to! 131, 161
    path.line_to! 369, 161
    path.line_to! 177, 301
    path.close_path
  end
end
canvas.save "star.svg"

Drawing not (yet) supported shapes

canvas = SVG::Canvas.new 100, 100
canvas << SVG::Node.new("circle",
  cx: 50,
  cy: 50,
  r: 30,
  fill: 'blue'
)
canvas.save "circle.svg"

About

A ruby library for generating SVG built on libxml-ruby

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages