<?php
function get_color($sample,$color) {
  switch($color) {
    case "red":
      $sample = substr($sample,0,2);
      break;
    case "green":
      $sample = substr($sample,2,2);
      break;
    case "blue":
      $sample = substr($sample,4,2);
      break;
    default:
      $sample = "00"; //should never get this! but just in case
  }
  return hexdec($sample);
}

$string = $_GET['message'];
$bgcolor = $_GET['bgcolor'];
$fgcolor = $_GET['fgcolor'];
$font   = 5;
$width  = ImageFontWidth($font) * strlen($string)+ImageFontWidth($font)*4;
$height = ImageFontHeight($font)+7;

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

$back = imagecolorallocate($im, 0, 0, 0);
$draw_color = imagecolorallocate ($im, (int)get_color($bgcolor,"red"), (int)get_color($bgcolor,"green"), (int)get_color($bgcolor,"blue"));
$text_color = imagecolorallocate ($im, (int)get_color($fgcolor,"red"), (int)get_color($fgcolor,"green"), (int)get_color($fgcolor,"blue"));

imageline($im, 0,2,$width,2,$draw_color);

imagefilledrectangle($im,0,4,$width,$height-5,$draw_color);

imageline($im, 0,$height-3,$width,$height-3,$draw_color);

imagestring ($im, $font, ImageFontWidth($font)*2, 3,  $string, $text_color);

$new_img = imagerotate ($im, 360-45, 0);

imagecolortransparent($new_img,$back);

header('Content-Type: image/png');

imagepng ($new_img);
imagedestroy ($im);
imagedestroy ($new_img);
?>