tp5.0Fatal error: Call to undefined function think\captcha\imagecreate()

Fatal error: Call to undefined function think\captcha\imagecreate() in F:\wamp\www\tpshop\vendor\topthink\think-captcha\src\Captcha.php on line 143


已标记关键词 清除标记
<div class="post-text" itemprop="text"> <p>'m trying the create my own Captcha to use on a webpage i'm working on. Since i'm pretty much a noob on php i followed a youtube guide</p> <p>i followed EVERY SINGLE STEP in this video, everything he did i did too, i dowloaded the same image lybrary(AnonymousClippings.tff btw) and etc BUT for some reason my captcha image is not showing.</p> <p>I have to files, one for the captcha and one for the index(to call the image function so i can see the image) and use it in a form.</p> <p>i'm sure the reason for not showing the image is pretty stupid but i just can't figure what's the problem.</p> <p>if you know a easier way to create my own captcha i would apreciate.</p> <p>captcha.php</p> <pre><code><?php class captcha{ private static $captcha = "__captcha__"; private static $font; private static $width = 70; private static $height = 70; private static $font_size = 40; private static $character_width = 40; private static function session_start(){ if(!isset($_SESSION)){ session_start(); } } private static function set_font(){ self::$font = self::$captcha; $AnonymousClippings = "HERE GOES ALL POSSIBLE CAHRS THAT THE CAPTCHA WILL BE ABLE TO SHOW FROM AnonymousClippings LYBRARY"; $handle = fopen(self::$font,"w+"); fwrite($handle, base64_encode($AnonymousClippings)); fclose($handle); return self::$font; } public static function get_random(){ $type = rand(0,2); switch ($type){ case 2: $random = chr(rand(65, 90)); break; case 1: $random = chr(rand(97, 122)); break; default: $random = chr(rand(0,9)); break; } return $random; } private static function get_width(){ return self::$width; } private static function get_height(){ return self::$height; } private static function generate_code($length){ self::session_start(); $code=null; for($i=0;$i<$length;$i++){ $code.=self::get_random(); } $_SESSION[self::$captcha] = $code; self::$width = $length * self::$character_width; return $code; } public static function image(){ $length = 6; $code = self::generate_code($length); self::set_font(); ob_start(); $image = imagecreatetruecolor(self::get_width(),self::get_height()); $white = imagecolorallocate($image, 255, 255, 255); imagefilledrectangle($image, 0, 0, self::get_width(), self::get_height(), $white); for($dot=0;$dot<2000;$dot++){ $red = rand(0,255); $green = rand(0,255); $blue = rand(0,255); $dot_color = imagecolorallocate($image, $red, $green, $blue); $x1 = rand(0,self::get_width()); $y1= rand(0,self::get_height()); $x2 = $x1 +1; $y2 = $y1 +1; imageline($image, $x1, $y1, $x2, $y2, $dot_color); } for($start = $length*(-1); $start<0; $start++){ $color = imagecolorallocate($image, rand(0,177), rand(0,177), rand(0,177)); $character = substr($code, $start,1); $x =($start+6)*self::$character_width; $y = rand(self::get_height()-20, self::get_height() -10); imagettftext($image, self::$font_size, 0, $x, $y, $color, self::$font, $character); } imagepng($image); imagedestroy($image); $source = ob_get_contents(); ob_end_clean(); unlink(self::$font); return "data:image/png;base64,".base64_encode($source); } public static function get_code(){ self::session_start(); return $_SESSION[self::$captcha]; } } ?> </code></pre> <p>index1.php</p> <pre><code><?php require_once("captcha.php"); if(isset($_POST["code"])){ if($_POST["code"]== captcha::get_code()){ echo "good"; }else{ echo "wrong"; } } ?> <form method="post"> <img src=" <?php captcha::image() ?>"/><br> <input type="text" name="code"/><br> <input type="submit" value="Check"/> </form> </code></pre> </div>
©️2020 CSDN 皮肤主题: 撸撸猫 设计师:C马雯娟 返回首页