【问题标题】:meteor-webshot is not working to take a screenshot and save it on the servermeteor-webshot 无法截取屏幕截图并将其保存在服务器上
【发布时间】:2014-08-17 23:33:39
【问题描述】:

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

我正在尝试将包 webshot 用于流星:

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
});

这是我调用服务器端拍摄网页的代码:

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~ 的目录,当我运行我的代码时,没有图像保存到该目录中,并且我没有收到任何错误。我不知道发生了什么!

由于我已经设置了我的流星以便能够在服务器端安装 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 使用 webshot 和常规 npm。但是我终于在使用meteor smart package时让它工作了,只要我添加

api.export("WEBSHOT","server");

到 webshot 的 package.js 文件。但它仍然没有实际截取屏幕截图。请有人提示我!

【问题讨论】:

    标签: node.js meteor phantomjs meteorite


    【解决方案1】:

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

    所以我尝试直接使用 phantomjs,顺序如下。

    1.安装phantomjs到服务器 2.将确切的phantomjs npm包版本添加到Meteor项目的packages.json文件中 3.在 Meteor 源码上使用 Meteor.require('phantomjs')

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

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

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,所以我使用最新版本的 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
      });
      

      【讨论】:

        猜你喜欢
        • 2010-11-03
        • 1970-01-01
        • 2023-01-31
        • 1970-01-01
        • 2013-02-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多