1

I have RaphaelJS based canvas, where user can do some work. I need to do 2 things:

  1. Save users work into database
  2. Rastersize SVG (I use Apache Batik for that task)

For 1 https://github.com/jspies/raphael.serialize dumps Raphael's canvas to json, then jQuery.getJSON() to send it to the backend, where I need to convert it back to SVG to feed into Batik.

Does this flow seem reasonable? SVG -> JSON -> SVG conversion seems a bit overhead, is there a better way to do this?

Backend runs python/django. I use standard json package for JSON -> SVG, but sometimes it fails with syntax errors in the incoming json (mainly in font style properties). Did anyone face these issues?

What's the best way to store this data in the database? Just as a string?

4

2 回答 2

2

Raphael.Export 在 Raphaël 支持的任何浏览器中将元素保存到 SVG:

https://github.com/ElbertF/Raphael.Export

我用它来使用 Batik 将 Raphaël 图纸保存为 PNG 服务器端。

于 2011-12-04T00:32:16.723 回答
0

如果您可以从 Raphael 获得根<svg>元素的句柄,那么您可以将其转换为原始 XML 源(在客户端)并发送:

var svgAsXML = (new XMLSerializer).serializeToString(svg);
于 2011-11-16T21:58:14.550 回答