<?php
function resizephoto($imgname,$filename,$new_w,$new_h){
	$system=explode('.',$imgname);
	if (preg_match('/jpg|jpeg/',$system[3])){
	$src_img=imagecreatefromjpeg($imgname);
	}
	if (preg_match('/png/',$system[3])){
	$src_img=imagecreatefrompng($imgname);	
	}
	
$old_w=imageSX($src_img);
$old_h=imageSY($src_img);

if (preg_match("/png/",$system[3]))
{
$imgheight=150; 
} else {
$imgheight=1200;
}

if ($old_h<=$imgheight) {
$thumb_h=$old_h;
$thumb_w=($old_w*$thumb_h)/$old_h;
}
else
{
$thumb_h=$imgheight;
$thumb_w=($old_w*$thumb_h)/$old_h;
}

if (preg_match("/png/",$system[3]))
{
$dst_img=imagecreatetruecolor($thumb_w,$thumb_h);
imagecolortransparent($dst_img, imagecolorallocatealpha($dst_img, 0, 0, 0, 127));
imagealphablending($dst_img, false);
imagesavealpha($dst_img, true);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_w,$old_h); 
imagepng($dst_img,$filename); 
} else {
$dst_img=imagecreatetruecolor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_w,$old_h); 
imagejpeg($dst_img,$filename); 
}

imagedestroy($dst_img); 
imagedestroy($src_img); 

}
?>