This is included within an HTML page that contains other code including start_session() at the top and the template HTML for the page layout. This is inside a <td>.
It displays photos ordered by catagory with a header for each catagory. The images have been uploaded by a user and so will be large. I'm trying to display them as thumbnails that you can then click to display the large image. I'll add that code once I get the thumbnails to work.
<?php
// include the database connection
include ("Includes/connection.php");
$query = "SELECT photo, catagory FROM photos GROUP BY catagory";
$result = mysql_query($query,$db)or die("Could not complete query ".mysql_error());
while ($row = mysql_fetch_array($result))
{
$var = $row['catagory'];
echo "<h3>".$var."</h3>";
$query2 = "SELECT photo, username FROM photos, users WHERE catagory = '".$var."' AND photos.userID = users.userID";
$result2 = mysql_query($query2, $db)or die("<br>Could not query database2<br>".mysql_error());
echo "<table><tr>";
while ($row2 = mysql_fetch_array($result2))
{
$image = "/var/www/vhosts/stoneycove.com/httpdocs/New Site/Images/Users Gallery/".$row2['photo'];
echo "<td valign='bottom' align='center'><img src='resize-image.php?image=".$image."'><br>".$row2['username']."</td>";
}
echo "</tr></table>";
}
?>
This then points to resize-image.php which has the code I showed earlier:
<?php
//destroy image first as the img tag that calls it is in a loop
if ($src) ImageDestroy($src);
if ($dst) ImageDestroy($dst);
if (!$max_width)
$max_width = 150;
if (!$max_height)
$max_height = 100;
$size = GetImageSize($image)or die("Could not get image size");
$width = $size[0];
$height = $size[1];
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if (($width <= $max_width) && ($height <= $max_height))
{
$tn_width = $width;
$tn_height = $height;
}
else if (($x_ratio $height) < $max_height)
{
$tn_width = $max_width;
$tn_height = ceil($x_ratio height);
echo "<br>tn_height: ".$tn_height;
}
else
{
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
$src = ImageCreateFromJpeg($image)or die("Could not create from Jpeg");
$dst = ImageCreateTrueColor($tn_width, $tn_height)or die("Could not create new image");
ImageCopyResized($dst, $src, 0,0,0,0, $tn_width, $tn_height, $width, $height)or die("Could not copy resized");
header('Content-type: image/jpg');
imagejpeg($dst, null, 75);
?>