Resizing images to a specific height
<p>I've currently implemented a piece of code allowing me to resize images to allow for thumbnails in a gallery I'm creating although it's not going too well.</p>

<p>I'm using some pre-written code to resize the images although I'm struggling with giving the images a minimum of 195px height and 195px width+ staying in proportion if possible.</p>

<p>Also would there be any way of optimising the images allowing page load times to be improved?</p>

<p>Here's my current code, any help would be greatly appreciated, thanks!</p>

<pre><code>function imageResize() {
$filename = $row['main'];

if (exif_imagetype($filename) == IMAGETYPE_GIF) {
    $create = imagecreatefromgif;
}

if (exif_imagetype($filename) == IMAGETYPE_JPEG) {
    $create = imagecreatefromjpeg;
}

if (exif_imagetype($filename) == IMAGETYPE_PNG) {
    $create = imagecreatefrompng;
}

$width = 600; //These values have been tinkered with from their original values
$height = 500;

header('Content-Type: image/jpeg');

list($width_orig, $height_orig) = getimagesize($filename);

$ratio_orig = $width_orig/$height_orig;

if ($height_orig &lt; 300) {
   $width = $height*$ratio_orig;
} else {
   $height = $width/$ratio_orig;
}

$image_p = imagecreatetruecolor($width, $height);
$image = $create($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

imagejpeg($image_p, null, 100);
}
</code></pre>
