Jump to content

imagettftext() problem


Paldo

Recommended Posts

Hi I have a problem to make captch working.

It says Warning: imagettftext(): supplied argument is not a valid Image resource in /3w/euweb.cz/p/parobek/captcha.php on line 38

 

<html>
<body>
<?php
function rand_str($length = 5, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890')
{
    // Length of character list
    $chars_length = (strlen($chars) - 1);

    // Start our string
    $string = $chars{rand(0, $chars_length)};
   
    // Generate random string
    for ($i = 1; $i < $length; $i = strlen($string))
    {
        // Grab a random character from our list
        $r = $chars{rand(0, $chars_length)};
       
        // Make sure the same two characters don't appear next to each other
        if ($r != $string{$i - 1}) $string .=  $r;
    }
   
    // Return the string
    return $string;
}

$retazec = rand_str();

echo $retazec;

$captcha = @imagecreatefrompng('captcha.png');

$font = 'arial.ttf';
                                         // THIS IS THE LINE THAT WARNING REFERS TO
imagettftext($captcha, 20, 0, 10, 20, $black, $font, $retazec);

?>
</body>

Link to comment
Share on other sites

Your error tells you you are using an invalid image resource. So look at your image resource.  Maybe captcha.png doesn't exist.  Maybe you spelled it wrong or forgot the path.  It doesn't help that you are suppressing any errors that might show up, putting that @ in front of it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.