Re: Modernizr tests for SVG (Was: Re: SVG IG Reset (introducing myself))

Hi Erik,

> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <svg id="testsvg" xmlns="http://www.w3.org/2000/svg" width="8" height="8"
> viewBox="0 0 8 8">
>  <filter id="flood" x="0" y="0" width="1" height="1">
>    <feFlood flood-color="lime"/>
>  </filter>
>  <rect fill="red" filter="url(#flood)" width="8" height="8"/>
> </svg>
> </head>
> <body>
> <canvas width="8" height="8"/>
> <script>//<![CDATA[
> var canvas = document.getElementsByTagName("canvas")[0];
> var ctx = canvas.getContext("2d");
> ctx.fillStyle = "red";
> ctx.fillRect(0,0,canvas.height,canvas.height);
> ctx.drawImage(document.getElementById("testsvg"), 0, 0, canvas.width,
> canvas.height);
> var pixels = ctx.getImageData(0,0,1,1);
> alert(pixels.data[0] == 0 &&
>      pixels.data[1] == 255 &&
>      pixels.data[2] == 0 &&
>      pixels.data[3] == 255);
> //]]></script>
> </body>
> </html>
>
> This fails in Opera due to bug CORE-15553 (security exceptions are thrown if
> an svg has been rendered to the canvas), but if that was fixed the above
> would alert true.

I would love if this worked in browsers, because it would allow you to
automate tests (check pixel data and report results in the DOM) and
I'm also looking for a nice way to serialize an SVG to PNG on the
client side.

Regards,
Jeff

Received on Wednesday, 3 February 2010 14:31:32 UTC