Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Construct image from Fabric.js JSON on python server

Using python, is it possible to reconstruct an image from the json representation of a fabric.js canvas?

It's easy to do with Node.js but I am using django so I prefer not having to run a separate node.js server just to create these images to send them to my django server.

like image 944
bab Avatar asked Oct 19 '13 22:10

bab


1 Answers

No.

I don't see how it's possible without writing Python port of Fabric (or a custom parser+renderer).

Here's why:

JSON data string contains custom representation of various Fabric shapes, which — during parsing and interpretation by Fabric's loadFromJSON — are all loaded and rendered onto canvas. The canvas could then be used to generate an image.

You can parse data in python, since it's just JSON. You can walk over it and analyze it. You'll even be able to "see" the kinds of shapes that need to be loaded onto canvas. But you'll still need the main thing — creating visual representation of each of those shapes.

Unless you do that manually (using some kind of graphics methods in Python; which sounds like a whole lot of work), I don't think there's much else that can be done.

like image 148
kangax Avatar answered Sep 27 '22 23:09

kangax