nodeJS上的结构,根本没有图像呈现

时间:2016-01-12 16:16:18

标签: node.js ubuntu canvas fabricjs node-canvas

问题出在Ubuntu 14.04上: NodeJS:0.10.32 画布:1.3.6 面料:1.6.0-rc.1

示例JSON:

{
"objects": [{
    "id": 0,
    "name": "1452525510_death_star.svg",
    "type": "image",
    "originX": "left",
    "originY": "top",
    "left": 78,
    "top": 21,
    "width": 512,
    "height": 512,
    "fill": "rgb(0,0,0)",
    "stroke": null,
    "strokeWidth": 1,
    "strokeDashArray": null,
    "strokeLineCap": "butt",
    "strokeLineJoin": "miter",
    "strokeMiterLimit": 10,
    "scaleX": 0.46,
    "scaleY": 0.46,
    "angle": 0,
    "flipX": false,
    "flipY": false,
    "opacity": 1,
    "shadow": null,
    "visible": true,
    "clipTo": null,
    "backgroundColor": "",
    "fillRule": "nonzero",
    "globalCompositeOperation": "source-over",
    "transformMatrix": null,
    "_controlsVisibility": {
        "tl": false,
        "tr": true,
        "br": true,
        "bl": false,
        "ml": true,
        "mt": false,
        "mr": false,
        "mb": true,
        "mtr": true
    },
    "src": "http://somedomain.com/media/patterns/users/1fb158157a882d6a4c983ddc401101d1.svg",
    "filters": [{
        "type": "Tint",
        "color": "#c485c4",
        "opacity": 1
    }],
    "crossOrigin": "",
    "alignX": "none",
    "alignY": "none",
    "meetOrSlice": "meet"
}, {
    "id": 1,
    "name": "Baby inside",
    "type": "image",
    "originX": "left",
    "originY": "top",
    "left": 102,
    "top": 290,
    "width": 470,
    "height": 427,
    "fill": "rgb(0,0,0)",
    "stroke": null,
    "strokeWidth": 1,
    "strokeDashArray": null,
    "strokeLineCap": "butt",
    "strokeLineJoin": "miter",
    "strokeMiterLimit": 10,
    "scaleX": 0.5,
    "scaleY": 0.5,
    "angle": 0,
    "flipX": false,
    "flipY": false,
    "opacity": 1,
    "shadow": null,
    "visible": true,
    "clipTo": null,
    "backgroundColor": "",
    "fillRule": "nonzero",
    "globalCompositeOperation": "source-over",
    "transformMatrix": null,
    "_controlsVisibility": {
        "tl": false,
        "tr": true,
        "br": true,
        "bl": false,
        "ml": true,
        "mt": false,
        "mr": false,
        "mb": true,
        "mtr": true
    },
    "src": "http://somedomain.com/media/patterns/12.png",
    "filters": [{
        "type": "Tint",
        "color": "#FFFFFF",
        "opacity": 1
    }],
    "crossOrigin": "",
    "alignX": "none",
    "alignY": "none",
    "meetOrSlice": "meet"
}],
"background": "#b0b0b0",
"backgroundImage": {
    "id": 0,
    "name": "",
    "type": "image",
    "originX": "left",
    "originY": "top",
    "left": 0,
    "top": 0,
    "width": 470,
    "height": 574,
    "fill": "rgb(0,0,0)",
    "stroke": null,
    "strokeWidth": 1,
    "strokeDashArray": null,
    "strokeLineCap": "butt",
    "strokeLineJoin": "miter",
    "strokeMiterLimit": 10,
    "scaleX": 1,
    "scaleY": 1,
    "angle": 0,
    "flipX": false,
    "flipY": false,
    "opacity": 1,
    "shadow": null,
    "visible": true,
    "clipTo": null,
    "backgroundColor": "",
    "fillRule": "nonzero",
    "globalCompositeOperation": "source-over",
    "transformMatrix": null,
    "_controlsVisibility": null,
    "src": "http://somedomain.com/media/products/121_37_2.jpg",
    "filters": [],
    "crossOrigin": "",
    "alignX": "none",
    "alignY": "none",
    "meetOrSlice": "meet"
}

请注意,使用toJSON()导出的此JSON包含一些自定义字段:[name,id]。

这来自我的Node脚本:

 function savetoFile() {
  var jsonData = JSONfromAbove;
  var out = fs.createWriteStream(filepath);
  canvas = fabric.createCanvasForNode(470, 574);

  canvas.loadFromJSON(jsonData, function () {  
    CanvasZoom(parseInt(zoom), function(){
    console.log('after zooom');
    console.log(canvas.getObjects());

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

  });
}

function CanvasZoom(z, callback) {
      width = canvas.width;
      height = canvas.height;
      canvas.setWidth(width*z);
      canvas.setHeight(height*z);
      canvas.setZoom(z);
      canvas.renderAll.bind(canvas);
      callback();
  }

事实:

  1. 无论我添加什么类型的对象('image','path', 'path-group')他们根本没有渲染,除了文本和 也许(我没有测试过它)PATHS不是来自URL的。
  2. 在上面的JSON中 有背景img - 它也不会渲染。
  3. 完全没有错误,但是:

    OSX上相同的相同脚本工作正常但是:

    当我尝试添加“大”SVG文件时,它给了我: “给出的图像尚未完成加载” 适用于大量正常的PNG。

  4. “渲染”最终PNG的时间与对象数量及其图像大小成正比,这可能表明它们正在加载某种类型的井。

    我已经安装了所有依赖库。

    尝试添加一个类似于同一问题的对象:

    fabric.Image.fromURL('http://somedomain.com/media/patterns/12.png', function(oImg, e) {...});
    

    我打赌,对于node-canvas来说,无论如何都失败了。

    我花了差不多2天试图修复这个恶魔般的问题];>

1 个答案:

答案 0 :(得分:0)

他发现www.somedomain.com上的问题是httpasswd,因此它无法下载文件,但没有丢失任何错误。

当将1.6.0-rc1切换到1.5.X时会发生错误:"分段错误"。