Search code examples
phpscreenshotphantomjs

Phantomjs not creating screenshot


I was try to create a web screenshot with phantomjs,But alwaise it result a blank image.I am using Fedora OS.Here is my javascript.

screen.js

        var WebPage = require('webpage');
        page = WebPage.create();
        page.open('http://google.com');
        page.onLoadFinished = function() {
        page.render('googleScreenShot' + '.png');
        phantom.exit();}

And here is my php code

shot.php

     $exec = '/var/www/html/test/bin/phantomjs  /var/www/html/test/screen.js'; 
     $escaped_command = escapeshellcmd($exec);
     exec($escaped_command);

But the created image was blank.phantomjs have executre permission.Please help me


Solution

  • I am not sure but this may work,try it

        var WebPage = require('webpage');
        page = WebPage.create();
        page.open('http://google.com');
        page.onLoadFinished = function() {
                window.setTimeout(function () {
                page.render('googleScreenShot' + '.png');
                phantom.exit();
              }, 2000);
        }