A ruby library for generating SVG built on libxml-ruby
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
lib
spec
.gitignore
.rspec
.yardopts
Gemfile
README.md
Rakefile
svg.gemspec

README.md

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"