<?
	error_reporting(0);
	$sourcepic=$_GET[spic];
	$res=$_GET[res];
                if (eregi("\.(jpg|jpeg)$", $sourcepic)) $im = imagecreatefromjpeg($sourcepic);
                if ($im != ""){
                        $dims = explode("x", $res);
                        $newh = $dims[1];
                        $neww = $newh / imagesy($im) * imagesx($im);
                        if ($neww > imagesx($im)){
                                $neww = imagesx($im);
                                $newh = imagesy($im);
                        }
                        if ($neww > $dims[0]){
                                $neww = $dims[0];
                                $newh = $neww / imagesx($im) * imagesy($im);
                        }
                        $im2 = imagecreatetruecolor($neww, $newh);
                        imagecopyresampled($im2,$im,0,0,0,0,$neww,$newh,ImageSX($im),ImageSY($im));
		header("Content-type: IMAGE/JPEG");
		header("Content-disposition: attachment; filename=thumb.jpg");
		ImageJPEG($im2); 
		ImageDestroy($im2);
		ImageDestroy($im); 
	}else{
		header("Content-type: IMAGE/JPEG");
		header("Content-disposition: attachment; filename=thumb.jpg");
		readfile($sourcepic);
}
?>