Using rsvg/php to render SVGs on the server-side.

351 views
Skip to first unread message

Fabian

unread,
Jan 23, 2010, 12:08:11 PM1/23/10
to protovis
Hello,

I just wanted to share the following snippet, it depends on jquery,
rsvg and php.

Take your favorite protovis, insert an empty image tag with the
id="rendered_image" and append the following code to your javascript
+protovis:

===
...
vis.render();

$.post(
"rsvg_convert.php",
vis.scene[0].canvas.innerHTML,
function(d) {
$("#rendered_img").attr("src", "data:image/png;base64," + d.replace
(/[ \n\t]+/,''));
},
"text");
===

Also create a new file named rsvg_convert.php with the following
content:

===
<?php
header('Content-type: image/png');
file_put_contents("/tmp/my.a.svg", file_get_contents("php://input") );
passthru("rsvg-convert /tmp/my.a.svg | base64");
?>
===

This mechanism creates the SVG on the client side, is posting it to
the server which renders it and redirects the rendered base64 encoded
png back to the client.

Note:
- There are security concerns.
- Animation does not work.
- The rendered image might be rendered diefferently than in e.g.
firefox
- Many more.

Greetings
- fabian

Jamie Love

unread,
Jan 23, 2010, 6:28:44 PM1/23/10
to prot...@googlegroups.com
Awesome, thanks for sharing this.


--
You received this message because you are subscribed to the Google Groups "protovis" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protovis+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protovis?hl=en.


Reply all
Reply to author
Forward
0 new messages