Luno1599
20-10-2009, 08:09 PM
Hey,
I made this code, but it only echos one image and there is 7 images in that directory... but it only echos one image resized, how would I fix the code to echo all 7 one after the other??
CODE:
<?php
// Generates thumnail graphic
function doGD($path,$jpg) {
$jpgFile = "$path/$jpg";
$width = 120;
list($width_orig, $height_orig) = getimagesize($jpgFile);
$height = (int) (($width / $width_orig) * $height_orig);
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($jpgFile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, null, 60);
imagedestroy($image_p);
}
//define the path as relative
$path = "test/";
//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");
//running the while loop
while ($file = readdir($dir_handle))
{
if($file == "." || $file == ".."){
$file = "";
}else{
header('Content-type: image/jpeg');
doGD("$path","$file");
}
}
//closing the directory
closedir($dir_handle);
?>
Dan
I made this code, but it only echos one image and there is 7 images in that directory... but it only echos one image resized, how would I fix the code to echo all 7 one after the other??
CODE:
<?php
// Generates thumnail graphic
function doGD($path,$jpg) {
$jpgFile = "$path/$jpg";
$width = 120;
list($width_orig, $height_orig) = getimagesize($jpgFile);
$height = (int) (($width / $width_orig) * $height_orig);
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($jpgFile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, null, 60);
imagedestroy($image_p);
}
//define the path as relative
$path = "test/";
//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");
//running the while loop
while ($file = readdir($dir_handle))
{
if($file == "." || $file == ".."){
$file = "";
}else{
header('Content-type: image/jpeg');
doGD("$path","$file");
}
}
//closing the directory
closedir($dir_handle);
?>
Dan