2012-01-29 41 views
1

可能重複時錯誤:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in selectimagesx()和imagesy()創建TUMBNAIL

我想全自動創建頂帖縮略圖。所以我決定調整後與小尺寸的當前圖像使用它作爲TUMBNAIL利用這一點 - resize-class.php類,並寫了這樣的代碼:

// Include the class 
include("resize-class.php"); 

$top_posts = mysql_query("In this query I select top posts - the most viewed posts of the day") 
while ($row = mysql_fetch_array($top_posts)){ 
    $post_id = $row['post_id']; // defining the ID of the post as variable 
    $post_image = $row['post_image']; //defining the image of the post as variable 
    //save image 
    $resizeObj = new resize($post_image); // Initialise - load image 
    $resizeObj -> resizeImage(260, 210, 'exact'); // resizing $post_image with 'exact' option 
    $resizeObj -> saveImage('images/'.$post_id.'.jpg', 80); // saving thumbnail of $post_image to the storage 
} 

但在循環返回象這樣的錯誤:

Warning: imagesx() expects parameter 1 to be resource, boolean given in resize-class.php on line 34 

Warning: imagesy() expects parameter 1 to be resource, boolean given in resize-class.php on line 35 

Warning: imagecopyresampled() expects parameter 2 to be resource, boolean given in resize-class.php on line 77 

問題是什麼?

+0

你需要顯示我們的相關代碼'resize :: __ construct()','resize :: resizeImage()'和'resize :: saveImage()'。 – Bojangles 2012-01-29 00:14:26

+0

我已經提到它 - 在我的問題中的類。這裏是http://pastebin.com/mWHek5At – John 2012-01-29 00:15:57

+0

對不起,沒有看到鏈接。 – Bojangles 2012-01-29 00:17:05

回答

3

是不是$post_image應該是圖像的路徑? 如果其實際上是圖像的路徑..那麼我認爲有錯誤的路徑.. 試圖回聲$post_image,看看你得到什麼......

+0

是的,我用正確的文件路徑解決了這個問題。謝謝 – Kamlesh 2015-05-12 08:40:05