这是我的js代码:var page = require('webpage').create();
var address = 'http://baidu.com';//填写需要打印的文件位置
var output = './img/'+'xigua'+'.png';//存储文件路径和名称
page.viewportSize = { width: 100, height: 100 };//设置长宽
page.open(address, function (status) { if (status !== 'success') {
console.log('Unable to load the address!');
phantom.exit();
} else {
window.setTimeout(function () {
page.render(output);
phantom.exit();
}, 500);
}
});这是php代码:<?php$command = 'phantomjs '.'phantomjs\123.js'; //上面提到的js文件的路径exec($command,$out);使用以上的代码是可以截图并且保存的,但是无法动态生成图片名.比如现在需求是保存的图片名称是订单号,就不知道如何传值,然后尝试使用.php来保存上面的js代码,以为这样可以使用动态的名称了,但是也遇到比较多的问题,所以请教各位大神如何传值,才能让phantomjs保存图片名的时候实现动态定义?谢谢.
1 回答

holdtom
TA贡献1805条经验 获得超10个赞
给phantomjs传递参数,比如
phantomjs phantomjs/123.js tupianming
在phantomjs里获取参数
var args = require('system').args; //args[1]就是你传入的图片名称(tupianming) args[0]是js文件名
添加回答
举报
0/150
提交
取消