Graphicsmagick包错误

时间:2015-01-08 18:59:16

标签: meteor

我尝试使用cfs:graphicsmagick包来生成缩略图,但生成的所有内容都是空图像。

当我启动服务器时,事情看起来不错:

I20150108-10:43:14.698(-8)? => GraphicsMagick found
I20150108-10:43:14.901(-8)? available
=> Meteor server restarted

但似乎gm不可用:

if (gm.isAvailable) {
    console.log("gm is available");
}

并且控制台抛出错误:

Uncaught TypeError: Cannot read property 'isAvailable' of undefined

1 个答案:

答案 0 :(得分:5)

查看docs,看起来就像它在服务器端可用的gm范围,所以这里没有问题,你有console.log,很发现

现在你可以像这样使用fsCollection

Images = new FS.Collection("images", {
stores: [
  new FS.Store.FileSystem("images"),
  new FS.Store.FileSystem("thumbs", {
    transformWrite: function(fileObj, readStream, writeStream) {
      // Transform the image into a 10x10px thumbnail
      gm(readStream, fileObj.name()).resize('10', '10').stream().pipe(writeStream);
    }
  })
],
filter: {
  allow: {
    contentTypes: ['image/*'] //allow only images in this FS.Collection
  }
}
});

请记住gm它刚刚在服务器上提供,因此请在/server上使用或在if(isServer)上使用

试试这个

    if (Meteor.isServer) {
       if (gm.isAvailable) {
        console.log("gm is available and this console.log was printed from my own code");
      }
    }

告诉我是否有效

更新回答

如果您在服务器/客户端上声明FS.collection,我建议您在/lib/collection.js上声明收集

      //collections.js
      Adopcion = new FS.Collection("Adopcion", {
stores: [
  new FS.Store.FileSystem("images"),
  new FS.Store.FileSystem("thumbs", {
    transformWrite: function(fileObj, readStream, writeStream) {
      // Transform the image into a 10x10px thumbnail
      gm(readStream, fileObj.name()).resize('10', '10').stream().pipe(writeStream);
    }
  })
]
});

并在同一个文件上进行订阅      //collection.js     //订阅     if(Meteor.isClient){         Meteor.subscribe( 'Adopcion');     } 现在/server/publish.js只能发布发布功能

//Publish methods
   Meteor.publish('Adopcion', function(){
          return Adopcion.find();
        });

因此不需要Meteor.methods({})并且meteor将首先加载其集合,并且它们将在客户端/服务器上可用

看看并告诉我是否适合您

相关问题