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条)

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?