小编Adi*_*i's的帖子

生成验证码图像PHP

我想使用PHP imagettftext生成Captcha Image.以下是我的代码.它给出了一个空图像.我想解决这个问题.

我已经测试了代码,但无法找到为什么图像不是bieng显示,虽然我的随机文本被传递给验证码图像生成的功能.

<?php

    function generateRandomString($length = 10) {
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $randomString = '';
        for ($i = 0; $i < $length; $i++) {
            $randomString .= $characters[rand(0, strlen($characters) - 1)];
        }
        return $randomString;
    }

    function generateCaptchaImage($text = 'good'){
        echo $text;
        echo 'OK';
        // Set the content-type
        header('Content-Type: image/png');

        $width = 200;
        $height = 30;
        $font = 'ThisisKeSha.ttf';

        // Create the image
        $im = imagecreatetruecolor($width, $height);

        //ADD NOISE - DRAW background squares
        $square_count = 6;
        for ($i = 0; $i …
Run Code Online (Sandbox Code Playgroud)

php captcha text image imagettftext

2
推荐指数
1
解决办法
8953
查看次数

标签 统计

captcha ×1

image ×1

imagettftext ×1

php ×1

text ×1