Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically generate PNG from Raphael.JS image

I'm writing an app that lets users generate images with Raphael.JS. One of the secondary features I want is to generate a PNG of the Raphael canvas.

Here's the general pipeline in my head:

  1. User inputs parameters
  2. We generate JS with Raphael calls
  3. We generate a JS wrapper that does the above and calls .innerHTML on the containing div, giving us SVG (which we then send somewhere)
  4. We execute the JS wrapper
  5. The SVG is sent to ImageMagick and out pops a PNG

Step 4 is the step I need some guidance on. The user could be using IE; we have no guarantee that the JS is ever executed in an SVG browser. In any case, we'd need this to run server-side for it to be reliable. So here are the three possibilities I've come up with so far:

  • Install Firefox on the server and run the result of (3) in Firefox. This option sucks because installing FF means installing a bunch of X stuff on our server, running FF carries a lot of overhead, and I don't really want to muck about with tracking the process and killing it once it's done.
  • Use Node.js + jsdom (http://github.com/tmpvar/jsdom). Downside here is that it's not clear how supported jsdom is - the purported site, jsdom.org, doesn't really exist. Also, I can't find any documentation.
  • Maybe do something with Rhino? As far as I can tell, Rhino has even more meager DOM support than Node.

So...all three of those options kind of suck. I think. Am I wrong about something? Is there another way?

like image 750
rfrankel Avatar asked Oct 14 '22 02:10

rfrankel


1 Answers

Solved this with wkhtmltoimage. Ugly solution, but it works.

like image 69
rfrankel Avatar answered Oct 18 '22 23:10

rfrankel