2011-11-07 24 views
1

我試圖使用wkhtmltoimage在我的網站,但沒有工作 這裏是我的測試網站wkhtmltoimage的出放爲NULL

<?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相同的命令,這是我得到 [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) 

不同的網站給了我不同的消息。有沒有人知道發生了什麼事?我僱了做我的網站的人說,這是一個服務器的問題,並不想這樣做別的,我的網站主辦公司一直告訴我了shell_exec()工作正常並且wkhtmltoimage正確安裝....我需要幫助,雙方我付出的幫助我沒有幫助我。任何人都可以幫助嗎?

謝謝

回答

0

看來,這個問題實際上是在wkhtmltoimage,有它的bug報告。它似乎也已經修復了這個bug,但目前的穩定版本並沒有。你可能想考慮嘗試RC,看看是否能解決你的問題。但是,請注意,在生產環境中使用RC並不普遍。

2

根據我的知識,這是因爲在「robots.txt」文件中禁用權限。你的代碼和庫沒有問題。

只與包含在robots.txt中允許的權限,網站工作

你不會得到縮略圖yahoo.com,imdb.com等,但你可以得到縮略圖google.com,hotmail.com等

1

出現這種情況,當你到HTML道路是錯誤的,如果你已經給:

看來腳本就會犯糊塗;請檢查HTML路徑。

1

發生這種情況是因爲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/