【问题标题】:How to write text on image onfly in php?如何仅在 php 中在图像上写入文本?
【发布时间】:2012-03-18 18:31:26
【问题描述】:

我想制作带有一些文字的“onfly”图像。用php可以吗?我正在尝试这个,但没有输出,有人可以看我的代码吗?

function createCaptcha($string){
    $image = PATH_DIR . "blueprint/images/bg6.png";
    $text_vertical_position = 97;
    $font_size = 15;
    $color = '32a53d';
    Header ("Content-type: image/png");
    $color = convert_to_rgb($color);
    $info = GetImageSize($image);
    $width = $info[0];
    $height = $info[1];


    if (preg_match("/.gif/", $image)) {
        $image = imageCreateFromGif($image);
    } elseif (preg_match("/.png/", $image)) {
        $image = imageCreateFromPng($image);
    } elseif (preg_match("/.jpg/", $image)) {
        $image = imageCreateFromJpeg($image);
    } elseif (preg_match("/.jpeg/", $image)) {
        $image = imageCreateFromJpeg($image);
    }

    $imgcolor = ImageColorAllocate ($image, $color[0], $color[1], $color[2] );
    imagettftext($image, $font_size, 0, $start_length, $text_vertical_position,
                 $imgcolor, $font , $text);
    ImagePNG ($image);
    ImageDestroy ($image);
}

我正在使用 codeigniter 来制作它。

谢谢

【问题讨论】:

    标签: php image gd gd2


    【解决方案1】:

    你的函数参数好像有错误:$string不是$text

     imagettftext($image, $font_size, 0, $start_length, $text_vertical_position,
          $imgcolor, $font, $string);
    

    PS。如果您制作验证码 - 如果没有任何额外的图像失真,它将不可靠。

    为什么不使用现成的解决方案?

    http://www.phpcaptcha.org/

    http://www.captcha.ru/kcaptcha/

    【讨论】:

    • 我用过 kcaptcha 很简单
    猜你喜欢
    • 2016-12-25
    • 2020-02-25
    • 2012-05-27
    • 1970-01-01
    • 2011-10-13
    • 2010-09-26
    • 2016-09-29
    • 1970-01-01
    • 2020-12-01
    相关资源
    最近更新 更多