如果有人能幫助我解決這個問題,我將不勝感激。通過從表格中讀取路徑並從文件夾中檢索圖像來顯示圖像縮略圖
我有一個表,它存儲了一組圖像的文件路徑,例如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);
}
?>
請誰能告訴我在哪裏,我的錯誤的謊言?非常感謝您提供的任何幫助
的事情是,我將不得不調整大小的縮略圖之前顯示它的原始圖像。 – Kim 2011-03-25 14:26:50
雖然gd會擅長做 – Kim 2011-03-25 14:27:05
好的...爲此,我保存了兩份,一張縮略圖和一張原稿(當然是調整大小)。然後,當我需要時,我會調用縮略圖版本。我認爲如果您有很多照片/用戶,則需要更長時間才能進行大小調整。 – luckytaxi 2011-03-25 14:42:29