1 function VerifiImag(){ 2 3 # 准备画面资源 4 $im = imagecreatetruecolor(100, 40); 5 6 # 准备涂料 7 $black = imagecolorallocate($im, 0, 0, 0); 8 $gray = imagecolorallocate($im, 200, 200, 200); 9 10 # 背景填充 11 imagefill($im, 0, 0, $gray); 12 13 for ($i = 0; $i < 15; $i++) { 14 imagearc($im,mt_rand(0,100),mt_rand(0,50),mt_rand(0,150),mt_rand(0,50),mt_rand(0,150),mt_rand(0,150),$black); 15 } 16 17 # 随机码 18 $strarr = array_merge(range(0,9),range(a,z),range(A,Z)); 19 20 # 打乱数组 21 shuffle($strarr); 22 23 # 组合数组 24 $str=join(array_slice($strarr,0,4)); 25 26 # 字体 27 $file = "FZSTK.TTF"; 28 imagettftext($im,25,0,10,30,$black,$file,$str); 29 30 # 输出最终图像或保存最终图像 31 header("content-type:image/png"); 32 imagepng($im); 33 34 # 释放画面资源 35 imagedestroy($im); 36 }
原文:https://www.cnblogs.com/yachyu/p/10706267.html