我试着在我的站点上使用wkhtmltoimage,但不起作用这里是我的测试站点的代码
<?php
$output = shell_exec('/usr/local/bin/wkhtmltoimage --quality 95 --width 1024 --height 0 yahoo.com test1.jpg');
echo "<pre>$output</pre>";
?>输出只是一张空白页。有趣的是,当我运行shell_exec(ls -l);而不是shell_exec('/usr/local/bin/wkhtmltoimage --quality 95 --width 1024 --height 0 yahoo.com test1.jpg');时,它工作得很好,当我从我的ssh终端运行wkhtmltoimage --quality 95 --width 1024 --height 0 yahoo.com test1.jpg时,它给出了
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但它会继续创建jpg文件。
当我对yahoo.com尝试同样的命令时,我得到的catarplc@zenbile.com [~/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)不同的网站给我不同的信息。有人知道这是怎么回事吗?我雇来做我的网站的人说这是服务器问题,不想做其他任何事情,我的虚拟主机公司一直告诉我shell_exec()工作正常,wkhtmltoimage安装正确……我需要帮助,但我付钱帮助我的双方都没有帮助我。有谁能帮忙吗?
谢谢
发布于 2011-12-09 19:01:00
据我所知,这是因为"robots.txt“文件中的权限被禁用了。您的代码和库中没有任何问题。
它仅适用于在robots.txt中包含允许权限的网站
你不会得到yahoo.com,imdb.com等的缩略图,但你可以得到google.com,hotmail.com等的缩略图
发布于 2012-10-14 02:56:59
当您的HTML路径错误时会发生这种情况,如果您已经给出:
<a href="http"//wwww.google.com">google.com</a> 看起来这个脚本搞混了;一定要检查HTML路径。
发布于 2013-04-30 19:46:50
这是因为wkhtmltoimage需要一个X服务器实例来转换包含图像的网页。
长话短说,如果您正在运行X服务器,只需添加--use-xserver参数即可。
如果不这样做,则需要使用xvfb将命令包装在虚拟X服务器实例中。
sudo apt-get install xvfb
xvfb-run --server-args="-screen 0, 1280x1024x24" wkhtmltoimage --use-xserver http://yahoo.com test.pdf有关更详细的解释,请查看:http://blog.hugerepo.com/2013/04/28/what-is-the-qpixma/
https://stackoverflow.com/questions/8034109
复制相似问题