$max_width) { $diff1 = $tn_width - $max_width; if($diff1%2 != 0) $diff1 = $diff1 - 1; $x = $diff1 / 2; } else { $diff = $tn_height - $max_height; if($diff%2 != 0) $diff = $diff- 1; $y = $diff / 2; } ini_set('memory_limit', '32M'); if ($ext == "jpg") $src = imagecreatefromjpeg($upfile); else if ($ext == "gif") $src = imagecreatefromgif($upfile); else if ($ext == "png") $src = imagecreatefrompng($upfile); $dst = ImageCreateTrueColor($max_width, $max_height); imagecopyresampled($dst, $src, -$x, -$y, 0, 0, $tn_width, $tn_height, $width, $height); } else { $x_ratio = $max_width / $width; $y_ratio = $max_height / $height; if( ($width <= $max_width) && ($height <= $max_height) ) { $tn_width = $width; $tn_height = $height; } elseif (($x_ratio * $height) < $max_height) { $tn_height = ceil($x_ratio * $height); $tn_width = $max_width; } else { $tn_width = ceil($y_ratio * $width); $tn_height = $max_height; } ini_set('memory_limit', '32M'); if ($ext == "jpg") $src = imagecreatefromjpeg($upfile); else if ($ext == "gif") $src = imagecreatefromgif($upfile); else if ($ext == "png") $src = imagecreatefrompng($upfile); $dst = ImageCreateTrueColor($tn_width, $tn_height); imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height); } Imagejpeg($dst); ImageDestroy($src); ImageDestroy($dst); ?>