jakubfiala / atrament

A small JS library for beautiful drawing and handwriting on the HTML Canvas.
http://fiala.space/atrament/demo
MIT License
1.55k stars 116 forks source link

How do I export/import canvas data to/from JSON? #8

Closed amsourav closed 8 years ago

amsourav commented 8 years ago

Libraries like fabric.js and paper.js have a toJSON() to extract canvas data as JSON. Do you plan to implement it?

jakubfiala commented 8 years ago

Hello! Unlike fabric.js and paper.js, Atrament is entirely bitmap-based, i.e. it does not store the stroke coordinates etc. This is because it's not really meant for complex vector rendering, you could think of it as a simple canvas manipulation addon, rather than a rendering library.

So I'm afraid there's no way we can do JSON export. We do, however, allow you to export the image with the toImage method (see readme). This gives you a DataURI that you can use to download, save to a server, etc. You can also restore it to your canvas by making an Image object with it and using drawImage.