meteor-webshot无法截取屏幕截图并将其保存在服务器上

时间:2014-06-26 23:43:17

标签: node.js meteor phantomjs meteorite

在服务器上,我想截取外部链接的屏幕截图,并将其保存到文件夹中的服务器上。

我正在尝试使用webshot for meteor:

https://github.com/TimHeckel/meteor-webshot

但它不起作用。我使用mrt add webshot安装了软件包。包安装成功。根据此stackoverflow:How to use webshot with meteor

我能够编辑webshot的package.js文件,以便像这样导出WEBSHOT变量服务器端:

Package.on_use(function (api) {
    api.add_files("lib/webshot.js", "server");
    api.export("WEBSHOT","server"); // This was the new line added to export WEBSHOT
});

这是我在服务器端调用webshot的代码:

Meteor.methods 
  post: (postAttributes) ->
    console.log postAttributes.url // 'http://yahoo.com'
    _image = "myscreenshot.png";
    _res = WEBSHOT.snap(postAttributes.url, "public/exports~/" + _image,
      screenSize:
        width: 300
        height: 300
    )

我在公共文件夹中有一个名为exports~的目录,当我运行我的代码时,没有图像保存到目录中,我也没有收到任何错误。我不知道发生了什么!

由于我已经设置了我的meteor以便能够安装npm包服务器端,我还尝试使用常规旧的npm install webshot安装npm webshot包。

然后我尝试使用webshot = Meteor.require(' webshot')但它从未起作用,因为我无法启动应用程序,因为它一直崩溃,如:

node_modules/webshot/node_modules/phantomjs/node_modules/request/node_modules/node-uuid/test/test.html:1: bad formatting in HTML template........

所以我不能使用Meteor.require在常规的npm上使用webshot。但是,只要我添加

,我终于在使用流星智能包时工作了
api.export("WEBSHOT","server");

到webshot的package.js文件。但它实际上并没有拍摄截图。请有人告诉我!

2 个答案:

答案 0 :(得分:0)

我已经从meteor-phantomjs git-hub页面中追踪了你的问题。 我有同样的问题,使用meteor-phantomjs,现在我意识到我们需要将幻像直接包含在项目中,因为meteor-phantomjs只包装环境路径甚至它使用phantomjs-sun包。 (我不知道差异)

所以我试图直接使用phantomjs,这就是序列。

1.将phantomjs安装到Server 2.在Meteor项目中添加精确的phantomjs npm包版本到packages.json文件 3.在流星源上使用Meteor.require(' phantomjs')

但是还有另一个问题, 因为节点phantomjs npm包似乎只是在child_process上执行phantom-script.js文件而且全部! 所以我认为我们必须按照自己的意愿来执行和控制数据。

可能会有一些误解,因为我是Node&amp ;;的新手。流星, 但我希望这可能会有所帮助。 感谢。

答案 1 :(得分:0)

我遇到了同样的问题所以我使用最新版本的node-webshot(0.15.4)添加了一个新的Meteor包装器(https://atmospherejs.com/bryanmorgan/webshot)。你应该可以使用:

meteor add bryanmorgan:webshot

与node-webshot相同的API:

webshot("http://google.com", "/tmp/google.png", function (err) {
    // screenshot saved to /tmp/google.png
});