<?php 

function thumb($imgname,$width,$height){
	list($sw,$sh,$imgType) = getimagesize($imgname);
	$types = array('1' => 'gif', '2' => 'jpeg', '3' => 'png' );
	$createImg = 'imagecreatefrom'.$types[$imgType];
	$imgsrc = $createImg($imgname);


	$ratio_orig  =  $sw / $sh ;
	if ( $width / $height  >  $ratio_orig ) {
	    $width  =  $height * $ratio_orig ;
	} else {
	    $height  =  $width / $ratio_orig ;
	}

	$dimg = imagecreatetruecolor($width, $height);

	imagecopyresampled($dimg, $imgsrc, 0, 0, 0, 0, $width, $height, $sw, $sh);

	$save = 'image'.$types[$imgType];
	$save($dimg, 'new_' . $imgname);

	imagedestroy($imgsrc);
	imagedestroy($dimg);
}

thumb('me.jpg',200,200);





 ?>