dongqian9013 2011-03-25 14:12
浏览 59
已采纳

通过从表中读取路径并从文件夹中检索图像来显示图像缩略图

I would be grateful if anybody could help me out with this.

I have a table which stores the filepath of a set of images, e.g col filepath stores values like: ./phpimages/image3.jpg. Note that my images are stored in folder 'phpimages'

Now i want to loop through all the rows in my table and display thumbnails of the images.

Here is my code:

/

*************************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);
}

?>

Please can anyone tell me where my error lies? Many thanks for any help provided

  • 写回答

2条回答 默认 最新

  • dtzh131555 2011-03-25 14:18
    关注

    Why not just use <img src="">

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?