ah righto. Its basically two seperate bits of code that I've tried to stick together to form one that works the way I want it to.
if (isset($GET['image_id'])) {
$image_id = $GET['image_id'];
$query = "SELECT FROM tbl_images WHERE image_id = '$image_id'";
$result = mysql_query($query);
if(mysql_num_rows($result) == 1) {
$fileType = mysql_result($result, 0, "image_type");
$fileContent = mysql_result($result, 0, "image");
$im = imagecreatefromstring($fileContent);
$width = imagesx($im);
$height = imagesy($im);
$maxwidth = 760;
if ($width > $maxwidth){
$imgw = 740;
$imgh = $height / $width $imgw;
$image=imagecreatetruecolor($imgw,$imgh);
imagecopyresized($image,$im,0,0,0,0,$imgw,$imgh,imagesx($im),imagesy($im));
$out = imagejpeg($image);
header("Content-type: $fileType");
echo $out;
} elseif ($width < $maxwidth) {
$query = "SELECT * FROM tbl_images WHERE image_id = '$image_id'";
$result = mysql_query($query);
$fileType = mysql_result($result, 0, "image_type");
$filecontent = mysql_result($result, 0, "image");
header("Content-type: $fileType");
echo $filecontent;
}
}
};
?>
Everything in blue is meant to check an image from a database and see if its width is bigger than 760px and resize it to 740 if it is, this is the bit that doesnt work and is taken from some code I used to resize images into thumbnails which does work.
The red code is the part that works and is for showing an image if it will already fit on the screen.