PhantomJs屏幕大师不保存图像而是输出文件

时间:2017-09-28 15:03:32

标签: javascript php node.js ubuntu phantomjs

我刚刚安装了PhantomJs并跟随instructions进行PHP屏幕捕获

但是当我加载

shot.php?url=google.com

我得到的是包含此代码的jobs文件夹中的文件

var page = require('webpage').create();

page.viewportSize = {width: 1024, height: 768};

page.open('http://google.com', function (status) {
    if (status !== 'success') {
        console.log('Unable to load the address!');
        phantom.exit(1);
    }


    page.evaluate(function() {
                    /* This will set the page background color */
            if (document && document.body) {
                document.body.bgColor = '#FFFFFF';
            }

            });

    setTimeout(function() {
            page.render('test.jpg');
            phantom.exit();
    }, 0);
});

我做错了什么?

1 个答案:

答案 0 :(得分:0)

首先,您需要替换screen-master/bin中的phantomJs文件 因为显然已经过时了......

秒而不是他们的演示我使用这个更简单的PHP代码

if (!isset($_GET['url'])) {
    exit;
}

require_once '../autoload.php';
use Screen\Capture;

$screen = new Capture($_GET['url']);
$screen->setImageType('png');

$t = time();
$t = date("Ymdhi", $t);

$filename = md5($_GET['url']);

$temp_dir = '/var/www/yoursite/screen-master/jobs/test/' . $filename . $t . '_1';
$screen->setWidth(370);
$screen->save($temp_dir);

位置目录,是的,它是绝对服务器路径,而不是相对

相关问题