I'm trying to display a directory full of images which are reduced in size. I'm not interested in thumbnails (and therefore omit the need for GD2??) Although my PHP version is 4.3.10 and as such has a bundled version of GD2 anyway.
I have got upto the point where the dir contents will display - only problem is the images are displayed in something like 1px by 1px.
Here's the code - as you can see, its simple code and the math is correct. It just won't work, what am i missing?
<?php
$count = 0;
$dir = "./images";
// open directory and parse file list
if (is_dir($dir))
{
if ($dh = opendir($dir))
{
while (($filename = readdir($dh)) !== false)
{
if (($filename != ".") && ($filename != ".."))
{
$image = "$dir./$filename.";
$image = str_replace(' ','%20',$image); //make sure file has correct url format
$max_width= "175";
$max_height= "175";
$resize_width= "175"; //same as max width
$resize_height= "175"; // same as max height
$size = getimagesize("$image");
$width= $size[0];
$height= $size[1];
if ($width>$max_width){
$new_width=$resize_width; // Resize Image If over max width
}else {
$new_width=$width; // Keep original size from array because smaller than max
}
if ($height>$max_height){
$new_height=$resize_height;
}else{
$new_height=$height;
}
$imageDone = "<img src=\"$image\" height=$new_height width=$new_width>";
echo "$imageDone";
echo "<br>";
$count ++;
}
}
// close directory
closedir($dh);
}
}
echo "-- $count FILES FOUND --";
?>
Any ideas much appreciated...