tags:

views:

243

answers:

3

Say I've written a simple app that draws circles in browser. Now I'd like to let people save their pictures. How would I store the data on the server? Which format would be the best option? Should I simply store the relevant html? What would be the case when I would want to make a custom format that is stored on the server and parsed back to html canvas when loaded?

+4  A: 

How would I store the data on the server?

Which format would be the best option?

Since they are just circles, you probably just need starting coordinate, size, line thickness, and colour. Sounds like its easy enough to store with SQL.

Should I simply store the relevant html?

What HTML? Drawings on canvas are not exposed in the DOM. That's why canvas is (currently) awful for accessibility (unlike SVG).

What would be the case when I would want to make a custom format that is stored on the server and parsed back to html canvas when loaded?

I'd transport it as JSON and then loop over the dataset with JS to redraw it.

David Dorward
A: 

canvas.toDataURL should allow you to do such things. check out canvaspaint.org's source code to see how to save on local computer and on server.

futtta
A: 

This might help: http://stackoverflow.com/questions/2808013/save-a-canvas-as-a-file-in-a-form.

This demo shows how to save locally -- though, for me at least, Save PNG (etc.) work in Firefox but not Chrome.

Sam Dutton