phpscreenshotwkhtmltoimage

Screenshot of website using PHP


Working on a small concept of taking screenshots of website by url now. By referring lot of websites used wkhtmltoimage. Currently using Mac. Installed wkhtmltoimage successfully, Also tried

wkhtmltoimage www.google.com ggss.png

in terminal. It successfully outputs the screenshot of website. But when i try executing the above command using PHP i dont see the output image or any errors. Below is the code i tried

<?php
$output = shell_exec('wkhtmltoimage http://www.bbc.com bbc.jpg');
?>

Any help would be appreciated


Solution

  • Ok finally executed the shell command through php via browser. So i thought i could share might be useful for someone. So the real problem is permission.

    So when i used whoami command on terminal output was macuser. But when i tried executing the command using shell_exec in php output was nobody. Its because apache didnt have permission. So i did the following to execute the shell command via PHP

    locate the httpd.conf file in /etc and find

    User nobody Group nogroup

    change the nobody to the username you'd like to set as the user you want to execute. For me its User macuser

    Then execute the following commands. (To make sure i executed them as su in terminal)

    now when i execute the following code it works

    <?php
    $output = shell_exec('/usr/local/bin/wkhtmltoimage http://www.google.com /Applications/XAMPP/xamppfiles/htdocs/demotasks/google.jpg');
    ?>
    

    Thanks to boulderapps!