使用GD的图像边框

时间:2013-01-29 10:40:39

标签: php joomla2.5

这是我的验证码图像脚本

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

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

1 个答案:

答案 0 :(得分:0)

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