title: Issue rendering SVG in Python using pyrsvg and Cairo
body: <p>I am having some trouble using the following code to render some SVG into PNG data. The StringIO writer is used since the image is ultimately intended for use as the body of an HTTP response.</p>
  
  <p>The result is a PNG of the correct dimensions, but it is completely transparent.</p>
  
  <pre><code>import rsvg
  import cairo
  import StringIO
  
  def render_svg_to_png(svg_data):
      # Render
      svg = rsvg.Handle()
      svg.write(buffer=svg_data)
  
      img = cairo.ImageSurface(cairo.FORMAT_ARGB32,
                               svg.props.width,
                               svg.props.height)
      ctx = cairo.Context(img)
      svg.render_cairo(ctx)
  
      # Write to StringIO
      png_io = StringIO.StringIO()
      img.write_to_png(png_io)
      img.finish()
  
      return png_io.getvalue()
  </code></pre>
  
  <p>The SVG data being rendered is as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
      &lt;!-- Created with Inkscape (http://www.inkscape.org/) --&gt;
  
  &lt;svg
      xmlns:dc="http://purl.org/dc/elements/1.1/"
      xmlns:cc="http://creativecommons.org/ns#"
      xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:svg="http://www.w3.org/2000/svg"
      xmlns="http://www.w3.org/2000/svg"
      xmlns:xlink="http://www.w3.org/1999/xlink"
      version="1.1"
      width="40"
      height="40"
      id="svg2"&gt;
      &lt;defs
          id="defs4"&gt;
          &lt;linearGradient
          id="linearGradient3769"&gt;
          &lt;stop
              id="stop3771"
              style="stop-color:#ffffff;stop-opacity:1"
              offset="0" /&gt;
          &lt;stop
              id="stop3773"
              style="stop-color:#000000;stop-opacity:1"
              offset="1" /&gt;
          &lt;/linearGradient&gt;
          &lt;radialGradient
          cx="13.895907"
          cy="15.277355"
          r="19.6875"
          fx="13.895907"
          fy="15.277355"
          id="radialGradient3775"
          xlink:href="#linearGradient3769"
          gradientUnits="userSpaceOnUse"
          gradientTransform="matrix(0.96746783,-0.96746783,0.95701248,0.95701249,-12.884457,12.690532)" /&gt;
      &lt;/defs&gt;
      &lt;metadata
          id="metadata7"&gt;
          &lt;rdf:RDF&gt;
          &lt;cc:Work
              rdf:about=""&gt;
              &lt;dc:format&gt;image/svg+xml&lt;/dc:format&gt;
              &lt;dc:type
              rdf:resource="http://purl.org/dc/dcmitype/StillImage" /&gt;
              &lt;dc:title&gt;&lt;/dc:title&gt;
          &lt;/cc:Work&gt;
          &lt;/rdf:RDF&gt;
      &lt;/metadata&gt;
      &lt;g
          transform="translate(0,-1012.3622)"
          id="layer1"&gt;
          &lt;path
              d="m 39.375,19.776785 a 19.6875,19.6875 0 1 1 -39.375,0 19.6875,19.6875 0 1 1 39.375,0 z"
              transform="matrix(1.015873,0,0,1.015873,0,1012.2715)"
              id="path2991"
              style="fill:url(#radialGradient3775);fill-opacity:1;fill-rule:nonzero;stroke:none" /&gt;
      &lt;/g&gt;
  &lt;/svg&gt;
  </code></pre>