fabricjs FabricJS canvas Serialization


Introduction

Once you have started building an application with FabricJS it won't be late when you realize that you will need to save results of the canvas/its contents to server. Or may exporting them as files to the client. For this very purpose you will need canvas serialization. Now some of you might ask Why Serialization we can save it as an image. So the answer would Saving image to a server needs bandwidth and text proves much better in this case.

Syntax

  1. JSON.stringify(canvas) - implicitly calls toJSON method on passed object. Gives String representation
  2. canvas.toObject() - returns the same representation as toJSON, only in a form of actual object
  3. canvas.toSVG() - returns an SVG representation of the canvas

Remarks

For more about FabricJS canvas serialization Refer the link Canvas Serialization