<?php
    function createImageNew($uploadedfile,$resn,$path=".",$name)
    {
        // Capture the original size of the uploaded image
		if(!$info=getimagesize($uploadedfile))
		return false;

		if(strtolower($resn)!="original" && $resn!="")
		{
			$resn=@explode("x",strtolower($resn));
			if(sizeof($resn)<2)
			$resn[] = $resn[0];
		}

        switch ($info['mime'])
        {
			case 'image/jpeg':
			$src = imagecreatefromjpeg($uploadedfile);
			break;
			case 'image/gif':
			$src = imagecreatefromgif($uploadedfile);
			break;
			case 'image/png':
			$src = imagecreatefrompng($uploadedfile);
			imagealphablending($src, true);
			break;
			default:
			return false;
        }

        $filename=$path."/".$name;

		$size = getimagesize($uploadedfile);

		if($resn != "original" && $resn != "")
		{
			$ratOrg = $size[0]/$size[1];
			$ratRez = $resn[0]/$resn[1];
			$ratDiff = $ratOrg/$ratRez;

			if($ratDiff<1)
			{
				$newHeight = round(($size[1]/$size[0])*$resn[0]);
				$newWidth  = $resn[0];
			}
			else
			{
				$newHeight = $resn[1];
				$newWidth = round(($size[0]/$size[1])*$resn[1]);
			}
		}
		else
		{
			$resn = array();
			$newWidth   = $resn[0] = $size[0];
			$newHeight  = $resn[1] = $size[1];
		}

        $tmp=imagecreatetruecolor($resn[0],$resn[1]);
		$xpos = (int)(($resn[0] - $newWidth)/2);
		$ypos = (int)(($resn[1] - $newHeight)/2);

		if($info['mime']=='image/png')
		{
			imagealphablending($tmp, false);
			imagesavealpha($tmp, true);
		}
        imagecopyresampled($tmp,$src,$xpos,$ypos,0,0,$newWidth,$newHeight,$size[0], $size[1]);

        switch ($info['mime'])
        {
			case 'image/jpeg':
			imagejpeg($tmp,$filename,66);
			break;
			case 'image/gif':
			imagegif($tmp,$filename,66);
			break;
			case 'image/png':
			imagepng($tmp,$filename);
			break;
        }

        imagedestroy($src);
        imagedestroy($tmp);
        return $name;
    }
?>
