HTML Canvas and Saving Data on the Server

Say I wrote a simple application that draws circles in a browser. Now I want people to save their photos. How to store data on the server? Which format would be the best option? Should I just store the appropriate html? What will happen if I want to create my own format, which is stored on the server, and after loading the parsing onto the html canvas?

+4
source share
3 answers

How can I store data on the server?

Which format would be the best option?

Since they are only circles, you probably just need the starting coordinate, size, line thickness, and color. It seems like it's fairly easy to store with SQL.

Should I just save the appropriate html?

What kind of HTML? Drawings on canvas are not displayed in the DOM. This is why the canvas (currently) is terrible for accessibility (unlike SVG).

What would be the case when I would like to create a non-standard format that is stored on the server and parsed back to the html canvas at boot time?

I port it as JSON and then go through the dataset with JS to redraw it.

+4
source

canvas.toDataURL should allow you to do such things. check canvaspaint.org source code to find out how to save it on the local computer and on the server.

+1
source

This may help: Save the <canvas> as a file in the form .

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

+1
source

Source: https://habr.com/ru/post/1302722/


All Articles