1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
<?php//1.qi enables the GD Library GD Library to provide a series of APIs for working with pictures, using the GD library to work with pictures, or to generate pictures. The GD library on the site is typically used to generate thumbnails or to add watermarks to images or to generate reports on Web site data. Session_Start (); //converting GBK encoded strings into UTF-8 strings, the first argument is written GBK because this php file is stored in the host code is GBK coding//UTF-8 Coding Browser general support, versatility, here is converted to UTF-8 $str = Iconv ("GBK", "Utf-8", "all mortal beings green mountains and monuments open Heart will be clouds unroll happiness will always accompany you"); if (!is_string ($str) | | |!mb_check_encoding ($STR, "Utf-8")) {exit ("not a string or not Utf-8"); $zhongwenku _size; Gets the length of the string by UTF-8 encoding $zhongwenku _size = Mb_strlen ($str, "UTF-8"); //Import the above characters into the array $zhongwenku = Array (); For ($i =0 $i < $zhongwenku _size $i + +) {$zhongwenku [$i] = Mb_substr ($str, $i, 1, "UTF-8");} $result = ""; //Picture four characters to write for ($i =0 $i <4; $i + +) {switch (rand (0, 1)) {case 0: $result. = $zhongwenku [rand (0, $zhongwenku _si ZE-1)]; Break Case 1: $result. =dechex (rand (0,15)); Break } } $_session["check" = $result; //Create a true Color picture width 100, high $img = Imagecreatetruecolor (100, 30); //distribution background color $BG = imagecolorallocate ($img, 0, 0, 0); //Assign text color $te = ImagecOlorallocate ($img, 255,255,255); //write String on the picture//imagestring ($img, Rand (3,8), Rand (1,70), Rand (1,10), $result, $te); //A special font can be written on the image according to the load font imagettftext ($img, Rand (2, 9), $te, "Msyh." TTF ", $result); $_session["Check" = $result; for ($i =0 $i <3; $i + +) {//$t = Imagecolorallocate ($img, rand (0, 255), rand (0, 255), rand (0, 255));//Draw line Imagelin E ($img, 0, rand (0), rand (70,100), rand (0), $te); $t = Imagecolorallocate ($img, rand (0, 255), rand (0, 255), rand (0, 255)); Add noise for the picture for ($i =0 $i <200; $i + +) {Imagesetpixel ($img, rand (1), rand (1,), $t);//Send HTTP header information Specifies that this time is sent in image JPEG header ("Content-type:image/jpeg"); Output JPEG image to browser imagejpeg ($IMG); ?> |