在服务器上,我想拍摄一个外部链接的屏幕截图,并将其保存到服务器的一个文件夹中。
我正在尝试使用meteor的webshot包:
https://github.com/TimHeckel/meteor-webshot
但它不起作用。我使用mrt add webshot安装了这个包。程序包已成功安装。根据这个堆栈溢出: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
});这是我调用服务器端获取网页截图的代码:
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 webshot包,使用常规的旧npm install 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........所以我不能使用webshot,常规的npm使用Meteor.require。但当我使用meteor智能包时,只要我添加了
api.export("WEBSHOT","server");添加到package.js文件中以进行网页截图。但它实际上并没有截取截图。有没有人给我点提示!
发布于 2014-08-07 01:14:33
我从meteor-phantomjs git-hub页面追踪到了你的问题。我在使用meteor-phantomjs时遇到了同样的问题,现在我意识到我们需要将phantom直接包含到项目中,因为meteor-phantomjs只包装了一个环境路径,甚至它也使用了phantomjs-sun包。(我不知道有什么不同)
所以我试着直接使用phantomjs,这是序列。
1.将phantomjs安装到服务器上2.将精确的phantomjs npm包版本添加到流星项目的packages.json文件中3.在流星源码上使用Meteor.require('phantomjs')
但还有另一个问题,因为node phantomjs npm包似乎只在child_process上执行phantom-script.js文件,仅此而已!所以我认为我们必须按照我们想要的方式来执行和控制数据。
可能会有一些误解,因为我是Node & Meteor的新手,但我希望这能有所帮助。谢谢。
发布于 2015-04-12 02:23:48
我也遇到了同样的问题,所以我使用最新版本的node-webshot (0.15.4)添加了一个新的流星包装器(https://atmospherejs.com/bryanmorgan/webshot),.You应该能够使用:
meteor add bryanmorgan:webshot和node-webshot相同的API:
webshot("http://google.com", "/tmp/google.png", function (err) {
// screenshot saved to /tmp/google.png
});https://stackoverflow.com/questions/24441963
复制相似问题