如果有人能帮助我解决这个问题,我将不胜感激。通过从表格中读取路径并从文件夹中检索图像来显示图像缩略图
我有一个表,它存储了一组图像的文件路径,例如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