简体   繁体   English

Farbic.js:有没有办法在JSON.stringify(canvas)生成的Json中保存url而不是svg图像的路径?

[英]Farbic.js: Is there any way to save url instead of paths of svg image in the Json generated by JSON.stringify(canvas)?

I'm trying to save fabric.js canvas to the server, but I got a lot of svg images.我正在尝试将 fabric.js 画布保存到服务器,但是我得到了很多 svg 图像。 I loaded them from URL (fabric.loadSVGFromURL).我从 URL (fabric.loadSVGFromURL) 加载它们。 When I use JSON.stringify(this.canvas), it saves the paths of the svg images into a Json.当我使用 JSON.stringify(this.canvas) 时,它会将 svg 图像的路径保存到 Json 中。 If I saved all the paths of them, the Json file will be too large, so I'm wondering if there is anyway that I can save only the url src of these SVG images (also I need to be able to load them to the canvas as well).如果我保存了它们的所有路径,则 Json 文件将太大,所以我想知道是否可以只保存这些 SVG 图像的 url src(我还需要能够将它们加载到画布也是)。

Thanks a lot!非常感谢!

If you don't need to change paths of svg you can just use svg as image.如果您不需要更改svg路径,则可以将 svg 用作图像。 It will work like this:它会像这样工作:

const canvas = new fabric.Canvas("c", { width: 600, height: 600 });

fabric.Image.fromURL("https://svgsilh.com/svg/309620.svg", (img) => {
  img.scaleToWidth(200);
  canvas.add(img);
  console.log(canvas.toJSON());
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM