organize images from directory in table
Posted: Wed Nov 01, 2006 12:49 pm
I am trying to come up with a script that will print my images in a table with 3 pictures per row automatically. Here is what I have so far:
Any ideas?
Code: Select all
if (is_dir("/reunion_photos/$id")) {
$dirname = "/reunion_photos/$id";
$dh = opendir($dirname) or die("<i>You have not added any pictures</i>");
while (false !== ($file = readdir($dh))) {
if ($file != "." && $file != "..") {
$image = "$dirname/$file";
$size = getimagesize("$image");
$height = $size[1];
$width = $size[0];
if ($height > 150)
{
$height = 150;
$percent = ($size[1] / $height);
$width = ($size[0] / $percent);
}
else if ($width > 150)
{
$width = 150;
$percent = ($size[0] / $width);
$height = ($size[1] / $percent);
}
for($x=1; $x<=1; $x++)
{
echo "<td align=\"center\"><img src=\"$image\" height=\"$height\" width=\"$width\"></td>";
if($x % 3 == 0)
{
echo "</tr>
<tr>";
}
}
}
}
closedir($dh);