-1

这是我的验证码图片脚本

    $width              = 100;
    $height             = 40;
    $im                 = @ImageCreate((int)$width, (int)$height);

    $bg                 = ImageColorAllocate($im, 255, 255, 255);

    $border             = ImageColorAllocate($im, 100, 120, 180);

    $text               = base64_decode($_GET["key"]);

    $textcolor          = ImageColorAllocate($im,20,40,75);

    for( $i=0; $i<($width*$height)/5; $i++ ) {
        imagefilledellipse($im, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $border);
    }
    for( $i=0; $i<($width*$height)/1000; $i++ ) {
        imageline($im, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $border);
    }

//  $font               = 10;
    $font               = $height * 0.28;

    $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);

    $textbox = imagettfbbox($font, 0, $font_fam, $text) or die('Error in imagettfbbox function');
    $x = ($width - $textbox[4])/2;
    $y = ($height - $textbox[5])/2;
    imagettftext($im, $font, 0, $x, $y, $textcolor, $font_fam , $text) or die('Error in imagettftext function');
//  ImageString($im, $font, $position_center, $position_middle, $text, $textcolor);
    Imagepng($im);
    header("Content-type: image/png");
    imagedestroy($im);

图像显示成功,我需要为此图像显示边框。

4

1 回答 1

0

您可以ImageRectangle($im, 0, 0, $width - 1, $height - 1, $color);在变量之后添加$textcolor. 我想这可能会对你有所帮助。

于 2013-01-29T10:42:36.947 回答