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 t开发者_如何学Chat 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
Why not just use <img src="">
You can output only one imagejpeg($thumb_image);
using this method. If you want to display all thumbnails in a combined image, you should merge your images to one PHP/GD image, and then output that one.
If you would like to output thumbnail images, then I advise you to use the following tool: http://phpthumb.sourceforge.net/
So when you iterate through your images, you should output an <img src="" />
for each thumbnail.
精彩评论