Here is my JS code:
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); }});
Here is the PHP code:
使用以上的代码是可以并且保存的,但是无法动态生成图片名.
比如现在需求是保存的图片名称是订单号,就不知道如何传值,然后尝试使用.php来保存上面的js代码,以为这样可以使用动态的名称了,但是也遇到比较多的问题,所以请教各位大神如何传值,才能让phantomjs保存图片名的时候实现动态定义?谢谢.
Reply content:
Here is my JS code:
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); }});
Here is the PHP code:
使用以上的代码是可以并且保存的,但是无法动态生成图片名.
比如现在需求是保存的图片名称是订单号,就不知道如何传值,然后尝试使用.php来保存上面的js代码,以为这样可以使用动态的名称了,但是也遇到比较多的问题,所以请教各位大神如何传值,才能让phantomjs保存图片名的时候实现动态定义?谢谢.
Pass parameters to Phantomjs, for example
phantomjs phantomjs/123.js tupianming
Get parameters in Phantomjs
var args = require (' system '). Args;//args[1] is the name of the image you passed in (tupianming) args[0] is the JS file name