无法在Node.js中使用Fabric.js设置stroke svg路径

时间:2013-11-09 08:09:24

标签: node.js path fabricjs stroke

我使用FabricJS和NodeJS来渲染SVG路径。 当我设置strokestrokeSize时,它没有显示笔画。我在一个矩形上测试它,它工作正常。我的代码:

var fabric = require('fabric').fabric,
    http   = require('http'),
    url    = require('url'),
    PORT   = 9099;

    var server = http.createServer(function (request, response) {
    var params = url.parse(request.url, true);
    var canvas = fabric.createCanvasForNode(400, 600);

    response.writeHead(200, { 'Content-Type': 'image/png' });

    canvas.backgroundColor = "blue";
    fabric.loadSVGFromURL('http://localhost/test/html5/fabric/img/animal1.svg', function(ob,op){
        var element = new fabric.PathGroup(ob, op);
        element.set({
        top:         100,
        left:        100,
        scaleX:      6,
        scaleY:      6,
        fill:        '#ddd',
        strokeWidth: 5,
        stroke:      '#555'
        });
        canvas.add(element);

        var rect = new fabric.Rect({
           left:            300,
           top:             100,
           width:           100,
           height:          100,
           fill:            '#ddd',
           strokeWidth:     3,
           strokeDashArray: [10, 5],
           stroke:          '#555'
        });
        canvas.add(rect);

        canvas.renderAll();

        var stream = canvas.createPNGStream();
        stream.on('data', function(chunk) {
            response.write(chunk);
        });
        stream.on('end', function() {
            response.end();
        });

    });
});

server.listen(PORT);

1 个答案:

答案 0 :(得分:0)

试试这个:

fabric.loadSVGFromURL('http://localhost/test/html5/fabric/img/animal1.svg', function(objects,options){
    var element = fabric.util.groupSVGElements(objects, options);
    element.set({
    top:         100,
    left:        100,
    scaleX:      6,
    scaleY:      6,
    fill:        '#ddd',
    strokeWidth: 5,
    stroke:      '#555'
    });
    canvas.add(element).renderAll();