Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 canvas image how can be saved in SVG or base 64 format?

can we export canvas image as svg or base 64 and then import it back again?

like image 859
Nitesh Avatar asked Nov 06 '22 08:11

Nitesh


1 Answers

It's not easy, no. There is no direct method to export Canvas graphics to SVG - they are fundamentally different types of representation, Canvas 2D uses a raster display, like television images, and SVG stores the geometric shapes, which can be resized without degradation of quality.

The simple answer is if you need SVG output, don't use canvas, start with SVG (the simpler SVG graphics library http://raphaeljs.com/ might be useful here).

The complex answer is - you could export to SVG if you record all the canvas operations you perform and have some way to recreate them with SVG, but, unless you have a restricted set of operations, that basically means you need to implement all canvas drawing functions and modes!

like image 139
andrewmu Avatar answered Nov 09 '22 03:11

andrewmu