$oh) { $nw = $w; $nh = unpercent(percent($nw, $ow), $oh); } else if ($oh > $ow) { $nh = $h; $nw = unpercent(percent($nh, $oh), $ow); } else { $nh = $h; $nw = $w; } } $out = imagecreatetruecolor($nw, $nh); imagecopyresampled($out, $tmp, 0, 0, 0, 0, $nw, $nh, $ow, $oh); imagedestroy($tmp); } else { echo 'Could not create image resource.'; exit; } if ($out) { switch (strtolower($type)) { case 'jpg': header('Content-type: image/jpeg'); imagejpeg($out); break; case 'gif': header('Content-type: image/gif'); imagegif($out); break; case 'png': header('Content-type: image/png'); imagepng($out); break; } imagedestroy($out); } else { echo 'ERROR: Could not create resized image.'; } ?>