<?
function jpgimage($filename,$upload_file3)
{
	// Content type
header('Content-type: image/jpeg');

// Get new dimensions
list($width, $height) = getimagesize($filename);

//gets the new value and applies the percentage, then rounds the value
$new_width3 = 370;
$new_height3 = 275; 

	
// Resample
$image_p3 = imagecreatetruecolor($new_width3, $new_height3);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p3, $image, 0, 0, 0, 0, $new_width3, $new_height3, $width, $height);
// Output
imagejpeg($image_p3, $upload_file3);	


unlink($filename);

round_img($upload_file3,$upload_file3);


}




function gifimage($filename,$upload_file3)
{
header('Content-type: image/gif');

// Get new dimensions
list($width, $height) = getimagesize($filename);

$new_width3 = 370;
$new_height3 = 275; 

	
// Resample
$image_p3 = imagecreatetruecolor($new_width3, $new_height3);
$image = imagecreatefromgif($filename);
imagecopyresampled($image_p3, $image, 0, 0, 0, 0, $new_width3, $new_height3, $width, $height);
// Output
imagegif($image_p3, $upload_file3);	


unlink($filename);

round_img($upload_file3,$upload_file3);
}


function pngimage($filename,$upload_file3)
{
header('Content-type: image/png');

// Get new dimensions
list($width, $height) = getimagesize($filename);

$new_width3 = 370;
$new_height3 = 275; 
	
// Resample
$image_p3 = imagecreatetruecolor($new_width3, $new_height3);
$image = imagecreatefrompng($filename);
imagecopyresampled($image_p3, $image, 0, 0, 0, 0, $new_width3, $new_height3, $width, $height);
// Output
imagepng($image_p3, $upload_file3);	


unlink($filename);
}

function round_img($image_file,$newimg)
{

$corner_radius =  15; // The default corner radius is set to 20px 
$topleft = true; // Top-left rounded corner is shown by default 
$bottomleft = true; // Bottom-left rounded corner is shown by default 
$bottomright = true; // Bottom-right rounded corner is shown by default 
$topright = true; // Top-right rounded corner is shown by default 
//$imagetype=strtolower($_GET['imagetype']); 
//$backcolor=$_GET['backcolor']; 
$imagetype=substr($image_file,-3,3); 
$backcolor="ffffff"; 


$endsize=$corner_radius; 
$startsize=$endsize*3-1; 
$arcsize=$startsize*2+1; 

if (($imagetype=='jpeg') or ($imagetype=='jpg')) { 
$image = imagecreatefromjpeg($image_file); 
} else { 
if (($imagetype=='GIF') or ($imagetype=='gif')) { 
$image = imagecreatefromgif($image_file); 
} else { 
$image = imagecreatefrompng($image_file); 
} 
} 

$arr=getimagesize($image_file);
$new_width3 = $arr[0]; 
$new_height3 = $arr[1];

// Top-left corner 
$background = imagecreatetruecolor($new_width3,$new_height3); 
imagecopymerge($background, $image, 0, 0, 0, 0, $new_width3, $new_height3, 100); 
$startx=$new_width3*2-1; 
$starty=$new_height3*2-1; 
$im_temp = imagecreatetruecolor($startx,$starty); 
imagecopyresampled($im_temp, $background, 0, 0, 0, 0, $startx, $starty, $new_width3, $new_height3); 
$bg = imagecolorallocate($im_temp, hexdec(substr($backcolor,0,2)),hexdec(substr($backcolor,2,2)),hexdec(substr($backcolor,4,2))); 
$fg = imagecolorallocate($im_temp, hexdec(substr($forecolor,0,2)),hexdec(substr($forecolor,2,2)),hexdec(substr($forecolor,4,2))); 

if ($topleft == true) { 
imagearc($im_temp, $startsize, $startsize, $arcsize, $arcsize, 180,270,$bg); 
imagefilltoborder($im_temp,0,0,$bg,$bg); 
} 

// Bottom-left corner 
if ($bottomleft == true) { 
imagearc($im_temp, $startsize, $starty-$startsize,$arcsize, $arcsize, 90,180,$bg); 
imagefilltoborder($im_temp,0,$starty,$bg,$bg); 
} 

// Bottom-right corner 
if ($bottomright == true) { 
imagearc($im_temp, $startx-$startsize, $starty-$startsize,$arcsize, $arcsize, 0,90,$bg); 
imagefilltoborder($im_temp,$startx,$starty,$bg,$bg); 
} 

// Top-right corner 
if ($topright == true) { 
imagearc($im_temp, $startx-$startsize, $startsize,$arcsize, $arcsize, 270,360,$bg); 
imagefilltoborder($im_temp,$startx,0,$bg,$bg); 
} 


$newimage = imagecreatetruecolor($new_width3,$new_height3); 
imagecopyresampled($image, $im_temp, 0, 0, 0, 0, $new_width3,$new_height3,$startx, $starty); 

// Output final image 
header("Content-type: image/png"); 
imagepng($image,$newimg); 
imagedestroy($image); 
imagedestroy($background); 
//imagedestroy($im_temp); 
}
?>

