<!DOCTYPE html>
<html>
	<head>
		<title>Generate Signature</title>
	</head>

	<body>
		<p>
		<?php
			$font_dir = 'fonts/';
			$image_dir = 'images/';
			$picture_dir = 'userpics/';

			if(isset($_POST['username'])){

				$error = 0;
				
				$username = $_POST['username'];
				$avatar = $_POST['avatar'];
				$motto = $_POST['motto'];

				if(strlen($username)>11){
					$error = 1;
					echo('Username too long!<br>');
				}

				if(strlen($motto)>16){
					$error = 1;
					echo('Motto too long!<br>');
				}
				
				if($username==''){
					$error = 1;
					echo('You must enter a username!<br>');
				}
				
				if($avatar==''){
					$error = 1;
					echo('You must choose an avatar!<br>');
				}

				if($motto==''){
					$error = 1;
					echo('You must enter a motto!<br>');
				}

				if($error ==0){
					
					$background = '';
					$background .= $image_dir."signature_".$avatar;
					$fontpath = $font_dir.'trajanProRegular.ttf';
					$username = strtoupper($username);
					$avatar = strtoupper($avatar);
					
					$img = imagecreatefrompng($background);

					$font_color = imagecolorallocate($img, 82, 41, 16);

					imagettftext($img, 36, 0, 177, 102, $font_color, $fontpath, $username);
					imagettftext($img, 24, 0, 179, 136, $font_color, $fontpath, $username);

					$r = rand(0,1000);
					
					$pic = $picture_dir.$username.$r.'.png';

					imagepng($img, $picture_dir);
					imagedestroy($img);
					
					echo('<img src = "'.$pic.'"/>');
					echo('<br/><br/>If you like the image please save it as we do not provide hosting.');
				}

			}

		?>
		</p>
		<p><a href="index.php">Create a new signature</p>
	</body>
</html>