2011-03-25 68 views
0

如果有人能幫助我解決這個問題,我將不勝感激。通過從表格中讀取路徑並從文件夾中檢索圖像來顯示圖像縮略圖

我有一個表,它存儲了一組圖像的文件路徑,例如col文件路徑存儲值如:./phpimages/image3.jpg。請注意,我的圖像存儲在文件夾'phpimages'

現在我想遍歷我的表中的所有行並顯示圖像的縮略圖。

這裏是我的代碼:

/

*************************Display all records from images table***************/ 
//create an instance is Image 
$objImage = new Image; 

$result = $objImage -> listImage(); 
$num_rows = mysql_num_rows($result); 
//echo $num_rows."records in database"; 


while($row = mysql_fetch_assoc($result)){ 

$imagepath="'".$row["filepath"]."'"; // note that if i put $imagepath= "dog.jpg", it displays the image just once! 


//set mime type content 
header('Content-Type: image/jpeg'); 


//create original image 
$image = imagecreatefromjpeg($imagepath); 

//get image dimension 
$dim=getimagesize($imagepath); 


//Set thumb dimension 
$thumbw = 100; 
$thumbh = 130; 

//create empty image 
$thumb_image=imagecreatetruecolor($thumbw, $thumbh); 

//Resize original image and copy it to thumb image 
imagecopyresampled($thumb_image, $image, 0, 0, 0, 0, 
        $thumbw, $thumbh, $dim[0], $dim[1]); 


//display thumb image 
imagejpeg($thumb_image); 
} 

?> 

請誰能告訴我在哪裏,我的錯誤的謊言?非常感謝您提供的任何幫助

回答

1

爲什麼不直接使用<img src="">

+0

的事情是,我將不得不調整大小的縮略圖之前顯示它的原始圖像。 – Kim 2011-03-25 14:26:50

+0

雖然gd會擅長做 – Kim 2011-03-25 14:27:05

+0

好的...爲此,我保存了兩份,一張縮略圖和一張原稿(當然是調整大小)。然後,當我需要時,我會調用縮略圖版本。我認爲如果您有很多照片/用戶,則需要更長時間才能進行大小調整。 – luckytaxi 2011-03-25 14:42:29

1

您可以使用此方法僅輸出一個imagejpeg($thumb_image);。如果您想在組合圖像中顯示所有縮略圖,則應將圖像合併到一個PHP/GD圖像,然後輸出該圖像。

如果你想輸出的縮略圖,那麼我建議你使用以下工具:通過您的圖片 http://phpthumb.sourceforge.net/

所以,當你重複,你應該爲每個縮略圖輸出<img src="" />

+0

你好,非常感謝您的建議......我不想顯示所有縮略圖在一個融合的形象,我想在一行中顯示每個縮略圖並追加其各自的信息。所以我假設我必須循環遍歷表格中的路徑併爲它們中的每一個生成縮略圖。我希望我很清楚。我有辦法做到這一點? – Kim 2011-03-25 14:21:05

+0

嗨伊米,非常感謝這個建議,我會嘗試這個工具.. – Kim 2011-03-25 14:32:10

相關問題