All pastes #241429 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-11-06 04:53 UTC
rendered paste body
<?

// Options
$fontsize = 			isset($_GET['fontsize']) 			? $_GET['fontsize'] 		: 24;
$font =		 			isset($_GET['font']) 				? $_GET['font'] 			: "AntsyPants";
$text =  				isset($_GET['text']) 				? $_GET['text'] 			: "TESTing";
$background_color =		isset($_GET['background_color']) 	? $_GET['background_color'] : "grey";
$font_color =  			isset($_GET['font_color']) 			? $_GET['font_color'] 		: "blue";
$image_type =  			isset($_GET['image_type']) 			? $_GET['image_type'] 		: "GIF";

$padding = 25; // Padding in pixels.
$shadow_distance = 2; // Distance of Shadow from Text

// Determine font

if (  $font == "AntsyPants" )
{
	$font = 'AntsyPants.ttf';
}

$boundingbox = @imagettfbbox($fontsize, 0, $font, $text);
$text_width = abs($boundingbox[4] - $boundingbox[0]);
$text_height = abs($boundingbox[5] - $boundingbox[1]);

$imagewidth = $text_width + ($padding * 2);
$imageheight = $text_height + ($padding * 2);

// Create the Image
$im = imagecreatetruecolor($imagewidth, $imageheight);

$xcord = ($imagewidth / 2) - ($text_width / 2);
$ycord = ($imageheight / 2) + ($text_height / 2) - 2;

// Fill Background
switch ($background_color)
{
   case 'grey':
		$color = imagecolorallocate($im, 128, 128, 128);
		break;
   case 'black':
		$color = imagecolorallocate($im, 0, 0, 0);
		break;
   case 'blue':
		$color = imagecolorallocate($im, 14, 37, 216);
		break;
   case 'white':
   default:
		$color = imagecolorallocate($im, 255, 255, 255);
		break;
}

imagefilledrectangle($im, 0, 0, $imagewidth, $imageheight, $color);

// Create Text
switch ($font_color)
{
   case 'grey':
		$color = imagecolorallocate($im, 128, 128, 128);
		break;
   case 'white':
		$color = imagecolorallocate($im, 255, 255, 255);
		break;
   case 'blue':
		$color = imagecolorallocate($im, 14, 37, 216);
		break;
   case 'black':
   default:
		$color = imagecolorallocate($im, 0, 0, 0);
		break;
}

// Display Shadow
$shadow = imagecolorallocate($im, 60, 60, 60);
imageTTFText($im, $fontsize, 0, $xcord + $shadow_distance, $ycord + $shadow_distance, $shadow, $font, $text);

// Display Text
imageTTFText($im, $fontsize, 0, $xcord, $ycord, $color, $font, $text);

// Display Image
if ( $image_type == "GIF" )
{
	header("Content-type: image/gif");
	imagegif($im);
}
elseif ( $image_type == "JPG" )
{
	header("Content-type: image/jpg");
	imagejpeg($im);
}
elseif ( $image_type == "PNG" )
{
	header("Content-type: image/png");
	imagepng($im);
}

// Destroy Image
imagedestroy($im);

?>