Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 29th, 2012  |  syntax: None  |  size: 0.75 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # encoding: utf-8
  2.  
  3. require 'rubygems'
  4. require 'builder'
  5.  
  6. svg_doctype = [
  7.   :DOCTYPE,
  8.   :svg,
  9.   :PUBLIC,
  10.   "-//W3C//DTD SVG 1.1//EN",
  11.   "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"
  12. ]
  13.  
  14. svg_options = {
  15.   :xmlns         => "http://www.w3.org/2000/svg",
  16.   :"xmlns:xlink" => "http://www.w3.org/1999/xlink",
  17.   :"xmlns:ev"    => "http://www.w3.org/2001/xml-events",
  18.   :version       => "1.1",
  19.   :baseProfile   => "full",
  20.   :width         => "1000px",
  21.   :height        => "1000px"
  22. }
  23.  
  24. output = String.new
  25. svg = Builder::XmlMarkup.new indent: 2, target: output
  26. svg.instruct!
  27. svg.declare! *svg_doctype
  28.  
  29. svg.svg(svg_options) do
  30.   svg.circle cx: 500, cy: 500, r: 200, style: "fill:red; stroke:black; stroke-width:10"
  31. end
  32.  
  33. File.open('output.svg', 'w') { |f| f.write output }