<?
 // 회원 가입시 입력하는 자동가입방지 문자열 이미지 만들기

 function randText($strSize)
 {
  $str = "";
  for ($i=0; $i<$strSize; $i++) 
   {
   $num = rand() % 52;
   if ($num < 26) $str .= chr($num + 65); // 대문자
   else $str .= chr($num + 97 - 26); //소문자 출력
  }
  return $str;
 }

 $fontname = "./malgun.ttf"; // php 파일과 같은 디렉토리거나, 경로까지 설정해야함
    $width = "500"; 
    $height = "500"; 

 function euckr2utf8($text) {
  return stripslashes(iconv("EUC-KR","UTF-8",$text));
 }

 $text = randText(5);
 $fontsize = 16;

 $bound = ImageTTFBBox($fontsize,0,$fontname, $text); 
    $imgWidth = $bound[2]+20; 
    $imgHeight = $fontsize*3.0; 
     
    $im=ImageCreate($imgWidth,$imgHeight); 
    $white = ImageColorAllocate ($im, 255, 255, 255); 
    $black = ImageColorAllocate ($im, 0, 0, 0); 

    ImageTTFText($im,$fontsize,rand()%20, 10, $imgHeight-10, $black, $fontname, $text); 
//    imagefilter($im, IMG_FILTER_MEAN_REMOVAL);

 header ("Content-type: image/png");
    ImagePNG($im);
    ImageDestroy($im);
?>