JavaScript-How to use PHANTOMJS to get screenshots and save

Source: Internet
Author: User
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  
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.