Can't load SVG from URL

自闭症网瘾萝莉.ら 提交于 2019-12-12 06:20:05

问题


I want to load different shapes in FabricJS based Canvas using loadSVGFromURL(), but can't. Documentation is also not complete on this. I just want a complete example. I can load it from string, but string creates spaces which creates problems when rendering. Here is my code:

var canvas = new fabric.Canvas('canvas');
        fabric.loadSVGFromURL('BlueFlower.svg', function (objects) {
            var SVG = fabric.util.groupSVGElements(objects, options);
            canvas.add(SVG).centerObject(SVG).renderAll();
            SVG.setCoords();
        });

回答1:


I have done an example on jsfiddle, that I create two objects and I load an svg image from url, you can take a look.

Here is an example

The snippet for load svg is this:

var site_url = 'http://fabricjs.com/assets/1.svg';

fabric.loadSVGFromURL(site_url, function(objects) {
  var group = new fabric.PathGroup(objects, {
    left: 165,
    top: 100,
    width: 295,
    height: 211
  });
  canvas.add(group);
  canvas.renderAll();
});


来源:https://stackoverflow.com/questions/29876146/cant-load-svg-from-url

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!