This is a library for building SVG images in ruby, using libxml-ruby
.
# 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"
# 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"
canvas = SVG::Canvas.new 100, 100
canvas << SVG::Node.new("circle",
cx: 50,
cy: 50,
r: 30,
fill: 'blue'
)
canvas.save "circle.svg"