A better version of the edit file:
thumb.php.inc
<?php
/* *********************************************************
* thumb.php.inc
* Author - Chris Mullins
* Date - Summer, 2005
* Purpose - Resizes a specified image and saves a thumbnail
* - of that image.
* ********************************************************* */
function createthumb($source, $fname, $x, $y) {
$xy = getimagesize($source);
if(!$x && !$y) { return 0; }
else {
$_e = explode('.', $source);
$e = $_e[sizeof($_e) - 1];
switch(strtolower($e)) {
case 'jpg':
case 'jpeg':
$im = imagecreatefromjpeg($source);
break;
case 'gif':
$im = imagecreatefromgif($source);
break;
case 'wbmp':
$im = imagecreatefromwbmp($source);
break;
case 'png':
$im = imagecreatefrompng($source);
break;
}
$im_x = imagesx($im);
$im_y = imagesy($im);
if($y == 0) {
$scale_x = $x / ($im_x - 1);
$scaley = $im_y * $scale_x;
}
else if($x == 0) {
$scale_y = $y / ($im_y - 1);
$scalex = $im_x & $scale_y;
}
/*
* Minimize strech distortions
*/
$hw = $im_y / $im_x;
if($hw > 1) {
$d_x = (int)($x / $hw);
$d_y = $y;
} else {
$d_y = (int)($y * $hw);
$d_x = $x;
}
echo "The image was resized to (".$d_x."x".$d_y.") to prevent size distortions<br /><br />";
$ot_im = imagecreatetruecolor($d_x, $d_y);
imagecopyresized($ot_im, $im, 0, 0, 0, 0, $d_x, $d_y, $im_x, $im_y);
imagedestroy($im);
/*
$o_im = imagecreatetruecolor($x, $y);
imagecopy($o_im, $ot_im, (($x - $d_x)/2), (($y - $d_y)/2), 0, 0, $x, $y);
imagedestroy($ot_im);
*/
$__turl_array = explode('.', $source);
$__turl_string = implode('.', array_splice($__turl_array, 0, sizeof($__turl_array) - 1));
$__turl_ext = $__turl_array[sizeof($__turl_array) - 1];
$url = $__turl_string . '.thumb.' . $__turl_ext;
/*
$background_color = imagecolorallocate($o_im, 0xFF, 0xFF, 0xFF);
if($x > $d_x) {
/*imagefilledrectangle($o_im, 0, 0, (($x - $d_x)/2), $y, $background_color);
imagefilledrectangle($o_im, ($x-(($x - $d_x)/2)), 0, $x, $y, $background_color);
$f_im = imagecreatetruecolor($d_x, $d_y);
} else {
imagefilledrectangle($o_im, 0, 0, $x, (($y - $d_y)/2), $background_color);
imagefilledrectangle($o_im, 0, ($y-(($y - $d_y)/2)), $x, $y, $background_color);
}
*/
imagejpeg($ot_im, $url);
imagedestroy($ot_im);
echo "Success! A <b>$e</b> thumbnail was generated for <a href=\"$source\"><b>$source</b></a> <br />";
}
}
?>
I'd post all my other gallery code, but it's split up into several files and I don't feel like searching for it.