wkhtmltoimage's out put is NULL

4.1k views Asked by At

i was trying to use the wkhtmltoimage on my site but is not working here is my code for the test site

<?php
$output = shell_exec('/usr/local/bin/wkhtmltoimage --quality 95 --width 1024 --height 0     yahoo.com test1.jpg');
echo "<pre>$output</pre>";
?>

the output is just a blank page. the funny thing is when i run the shell_exec(ls -l); instead of the shell_exec('/usr/local/bin/wkhtmltoimage --quality 95 --width 1024 --height 0 yahoo.com test1.jpg');, it works fine, when i run the wkhtmltoimage --quality 95 --width 1024 --height 0 yahoo.com test1.jpg from my ssh terminal, it gives me

Loading page (1/2)
Rendering (2/2)
QPixmap: Cannot create a QPixmap when no GUI is being used   ] 25%
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
Done

but it goes ahead and creats the jpg file.
when i try the same command for yahoo.com, this is what i get [email protected] [~/public_html]# wkhtmltoimage --quality 95 --width 1024 --height 0 yahoo.com test100.jpg

Loading page (1/2)
Error: Failed loading page http://yahoo.com (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://yahoo.com (sometimes it will work just to ignore this error with --load-error-handling ignore)

different websites gives me different messages. does anyboody know what's going on? the guy i hired to do my site says it's a server problem and doesn't wanna do anything else, my webhosting company keep telling me the shell_exec() is working fine and wkhtmltoimage is installed properly.... i need help and both parties that i paid to help me are not helping me. can anybody outhere help please???

Thank you

4

There are 4 answers

0
Berry Langerak On

It seems that the issue is actually in wkhtmltoimage, there's a bug report for it. It also seems the bug has been fixed, but not in the current stable. You might want to consider trying the RC and see if that fixes your problem. Mind, though, that using a RC in a production environment isn't generally advocated.

0
Hitesh On

This happens when your path to HTML is wrong if you have given:

<a href="http"//wwww.google.com">google.com</a> 

It seems the script gets confused; do check the HTML path.

0
João Daniel On

This is happening because wkhtmltoimage requires a X server instance to convert webpages that contain images.

Long story short, if you have a X server running, just add the --use-xserver argument.

If you don't, you need to use xvfb to wrap your command within a virtual X server instance.

sudo apt-get install xvfb
xvfb-run --server-args="-screen 0, 1280x1024x24" wkhtmltoimage --use-xserver http://yahoo.com test.pdf

For more detailed explanation, take a look at: http://blog.hugerepo.com/2013/04/28/what-is-the-qpixma/

0
umar On

According to my little knowledge, it is happening because the permissions are disabled in "robots.txt" file. There is no issue in your code and library.

It works only with websites that contains Allowed permissions in robots.txt

You wouldnt get thumbnail for yahoo.com, imdb.com etc but you can get the thumbnail for google.com, hotmail.com etc