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
https://forums.phpfreaks.com/topic/161272-imagettftext-problem/
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
https://forums.phpfreaks.com/topic/161272-imagettftext-problem/#findComment-851010
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.