javascript - Fabric.js going directly from JSON to PNG - Stack Overflow

I need to create PNG thumbnails of saved stringified JSON from fabric.js I have a database I am saving

I need to create PNG thumbnails of saved stringified JSON from fabric.js

I have a database I am saving the JSON data from the canvas to, but I need to create a PNG thumbnail gallery from this saved JSON data.

Rather than creating a bunch of canvases on the page and doing something like this.

canvas.loadFromJSON(JSONDATA); 
thumbImage = canvas.toDataURL('png');
$(this).attr('src', thumbImage);

I need to just directly create PNGs from the JSON Data. Is this possible, if so how do I do it?

I need to create PNG thumbnails of saved stringified JSON from fabric.js

I have a database I am saving the JSON data from the canvas to, but I need to create a PNG thumbnail gallery from this saved JSON data.

Rather than creating a bunch of canvases on the page and doing something like this.

canvas.loadFromJSON(JSONDATA); 
thumbImage = canvas.toDataURL('png');
$(this).attr('src', thumbImage);

I need to just directly create PNGs from the JSON Data. Is this possible, if so how do I do it?

Share Improve this question asked Oct 15, 2015 at 15:51 Anthony AllardAnthony Allard 836 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

you have an another alternative way is to creat a generation canvas and give it a none displaying, create a hidden canvas to generate your png's, like that you can have generated images from a hidden content canvas.

<canvas id='c' width='150' heigh='150' style='display: none;'><canvas>

<script>
    var canvas = new fabric.Canvas('c');
    canvas.loadFromJSON(json);
    canvas.toDataURL('png');
</script>

The JSON data is a set of instructions for FabricJS to use to create a canvas. A canvas can then be converted to an image.

For that reason, yes, you will need to create the canvas and then create the image.

An alternative method would be to create a server running NodeJS, which can run FabricJS. Ultimately you'd perform the same task there - create a canvas and then generate the image. But the benefit here is that being that it's a server process it would save the files directly to the server and thus this task could be automated.

But setting up the server and writing the script to perform this task may take more effort than your task requires - depends on how often you'll need to do this.

This post discusses how to install NodeJS and FabricJS. That'll get the server up and running, but you then need to also write the server script.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745442436a4627890.html

相关推荐

  • javascript - Fabric.js going directly from JSON to PNG - Stack Overflow

    I need to create PNG thumbnails of saved stringified JSON from fabric.js I have a database I am saving

    3小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信