I really don't know very much about PHP, but here goes...
So I'm trying to build a photo gallery for a website and I want it to be easy for the website owners to update and add pictures to their gallery... because they don't really know enough to do it themselves. (and I barely know enough to code something to make it easy for them !)
I jerry-rigged a script that allows pictures to be dropped into a folder, and then displayed on a page. and i've been toying with it, so that if they drop a picture too big into the folder, it will shrink it down to fit onto the page properly...
This is my first day playing with PHP so be kind D:
ANYWAYS, is there an easier way to have a script that keeps shrinking an image's width until it is 518 pixels wide? and then apply that same proportion to the height? -- my way works, but i get the feeling there might be an easier solution.
AND is it possible to control which files in the folder are opened first? perhaps via filemtime?
<?php
$a = '0';
$filepath = "photos";
$dir = dir($filepath);
echo "<table border=\"0\" cellpadding=\"2\" cellspacing=\"1\" width=\"520\" align=\"center\">";
while($entry=$dir->read()) {
if($entry == "." || $entry == "..") {
continue;
}
$fp = @fopen("$filepath/$entry","r");
$image_stats = GetImageSize($filepath."/".$entry);
$imagewidth = $image_stats[0];
$imageheight = $image_stats[1];
$ratio = ($imagewidth / 1.3);
$ratio2 = ($imagewidth / 1.5);
$ratio3 = ($imagewidth / 1.8);
if($ratio3 > "518") {
$w_ratio = ($imagewidth / 2.3);
$h_ratio = ($imageheight / 2.3);
} elseif ($ratio2 > "518") {
$w_ratio = ($imagewidth / 1.8);
$h_ratio = ($imageheight / 1.8);
} elseif ($ratio1 > "518") {
$w_ratio = ($imagewidth / 1.5);
$h_ratio = ($imageheight / 1.5);
} else {
$w_ratio = ($imagewidth / 1.3);
$h_ratio = ($imageheight / 1.3);
}
?>
<tr>
<td align="center">
<a href="<? echo "$filepath/$entry" ?>"><img src="<? echo "$filepath/$entry" ?>" width="<? echo "$w_ratio" ?>" height="<? echo "$h_ratio" ?>" border="1"></a>
</td>
<?
$a = $a + 1;
}
?>