Fabric.js: How to use predefined SVG filters?

倾然丶 夕夏残阳落幕 提交于 2019-12-24 09:01:08

问题


I have a lot of SVG images, with filter-animations defined inside of them. To describe the problem I made jsFiddle: http://jsfiddle.net/kinos/3vhtmsy5/47/ You can see there inline SVG, which is blinking with red alarm filter and fabric.js canvas with loaded SVG without blinking.

HTML (Inline SVG takes too much place to add it here):

<div id="svg"></div>
<canvas id="nativeCanvas"></canvas>

Javascript:

var canvas = new fabric.Canvas('nativeCanvas', {width: 1000, height: 600});
fabric.loadSVGFromString(document.getElementById('svg').innerHTML, function (objects, options) {
        var obj = fabric.util.groupSVGElements(objects, options);
        obj.set({left: 200, top: 250});
        canvas.add(obj);
    }, addSVGProperties);

    function addSVGProperties(el, obj) {
    obj.id = el.getAttribute('id');
}

I want to load predefined filters from SVG and manage them - apply/deapply to elements.

I made a small research, which described at google groups: https://groups.google.com/forum/#!topic/fabricjs/q1ASN-fsbpk

As a result I have found two problems:

  1. Fabric.js doesn't parse filters from SVG images
  2. Fabric.js have no option to apply it's own filters to loaded SVG(I'm not sure about this part).

And I see two options:

  1. Write lots of code to add filters parsing and applying.
  2. Find the way to use Fabric.js native filters.

Any ideas how to achive required behaviour without rewriting whole library? :)

来源:https://stackoverflow.com/questions/51819991/fabric-js-how-to-use-predefined-svg-filters

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