我正在创建验证码,这是我创建验证码图像的脚本。
header("Content-type: image/png");
$width = 100;
$height = 40;
$im = ImageCreate($width, $height);
$bg = ImageColorAllocate($im, 250, 250, 250);
$border = ImageColorAllocate($im, 191, 191, 191);
ImageRectangle($im, 0, 0, $width - 1, $height - 1, $border);
$text = base64_decode($GLOBALS["captcha_akey"]);
$textcolor = ImageColorAllocate($im,0,5,5);
$font = 3;
$font_width = ImageFontWidth($font);
$font_height = ImageFontHeight($font);
$text_width = $font_width * strlen($text);
$position_center = ceil(($width - $text_width) / 2);
$text_height = $font_height;
$position_middle = ceil(($height - $text_height) / 2);
ImageString($im, $font, $position_center, $position_middle, $text, $textcolor);
ImagePNG($im);
验证码显示正确,但在验证码顶部我发现了这个错误。
�PNG IHDRd(u�� PLTE������IDAT8�퓻 �0DU�M�R�Y"�*=���)C)T�"��pXH���$����|�˟�$�9N����$獌�@�54�i[ -Hi\ku7��&Y���АLA�h;�Ah�^u�*���5 I:;���\�pd;��;ߓ�6b�(���'P�SY���IEND�B`�