Php 通过从表中读取路径并从文件夹中检索图像来显示图像缩略图
如果有人能帮我解决这个问题,我将不胜感激 我有一个存储一组图像的文件路径的表,例如col filepath存储的值如下:./phpimages/image3.jpg。请注意,我的图像存储在“phpimages”文件夹中 现在,我想在表格中的所有行中循环并显示图像的缩略图 这是我的密码: /Php 通过从表中读取路径并从文件夹中检索图像来显示图像缩略图,php,Php,如果有人能帮我解决这个问题,我将不胜感激 我有一个存储一组图像的文件路径的表,例如col filepath存储的值如下:./phpimages/image3.jpg。请注意,我的图像存储在“phpimages”文件夹中 现在,我想在表格中的所有行中循环并显示图像的缩略图 这是我的密码: / 谁能告诉我我的错误在哪里?非常感谢您提供的任何帮助您只能输出一张imagejpeg($thumb\u image)使用此方法。如果希望在一个组合图像中显示所有缩略图,则应将图像合并到一个PHP/GD图像中,然
谁能告诉我我的错误在哪里?非常感谢您提供的任何帮助您只能输出一张
imagejpeg($thumb\u image)代码>使用此方法。如果希望在一个组合图像中显示所有缩略图,则应将图像合并到一个PHP/GD图像中,然后输出该图像
如果您想输出缩略图,我建议您使用以下工具:
因此,当您迭代图像时,您应该为每个缩略图输出一个
。为什么不直接使用
嗨,非常感谢您的建议…我不想在一个图像中显示所有缩略图,我想在一行中显示每个缩略图,并将其各自的信息附加到其中。因此,我假设我必须循环表中的路径,并为每个路径生成缩略图。我希望我说得够清楚了。我有办法吗?问题是,在显示之前,我必须将原始图像调整为缩略图的大小。啊,好的。。。为此,我保存了两份副本,一份缩略图和一份原件(当然,已调整大小)。然后在需要时调用缩略图版本。我认为如果你有很多照片/用户,那么动态调整大小需要更长的时间。是的,没错。我选择了这条路。谢谢你的建议,干杯
*************************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);
}
?>