2011-03-25 140 views
0

如果有人能帮助我解决这个问题,我将不胜感激。通过从表格中读取路径并从文件夹中检索图像来显示图像缩略图

我有一个表,它存储了一组图像的文件路径,例如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); 
} 

?> 

请谁能告诉我在哪里,我的错误的谎言?非常感谢您提供的任何帮助

回答

1

为什么不直接使用<img src="">

+0

的事情是,我将不得不调整大小的缩略图之前显示它的原始图像。 – Kim 2011-03-25 14:26:50

+0

虽然gd会擅长做 – Kim 2011-03-25 14:27:05

+0

好的...为此,我保存了两份,一张缩略图和一张原稿(当然是调整大小)。然后,当我需要时,我会调用缩略图版本。我认为如果您有很多照片/用户,则需要更长时间才能进行大小调整。 – luckytaxi 2011-03-25 14:42:29

1

您可以使用此方法仅输出一个imagejpeg($thumb_image);。如果您想在组合图像中显示所有缩略图,则应将图像合并到一个PHP/GD图像,然后输出该图像。

如果你想输出的缩略图,那么我建议你使用以下工具:通过您的图片 http://phpthumb.sourceforge.net/

所以,当你重复,你应该为每个缩略图输出<img src="" />

+0

你好,非常感谢您的建议......我不想显示所有缩略图在一个融合的形象,我想在一行中显示每个缩略图并追加其各自的信息。所以我假设我必须循环遍历表格中的路径并为它们中的每一个生成缩略图。我希望我很清楚。我有办法做到这一点? – Kim 2011-03-25 14:21:05

+0

嗨伊米,非常感谢这个建议,我会尝试这个工具.. – Kim 2011-03-25 14:32:10

相关问题