<? Php // 1. qi enables the gd library of the GD library to provide a series of APIS for image processing. The GD library can be used to process images or generate images. // The GD library on the website is usually used to generate thumbnails, add watermarks to images, or generate reports on website data. Session_start (); // The GBK encoding string into a UTF-8 string, the first parameter is written GBK, because the PHP file stored in the host encoding is GBK Encoding // UTF-8 coding browser universal support, versatility, here is converted to UTF-8 $ Str = iconv ("GBK", "UTF-8", "all sentient beings, green mountains, mountains, scenic spots, and monuments will always be with you "); If (! Is_string ($ str) |! Mb_check_encoding ($ str, "UTF-8 ")) { Exit ("not a string or not UTF-8 "); } $ Zhongwenku_size; // Obtain the length of the string by UTF-8 Encoding $ Zhongwenku_size = mb_strlen ($ str, "UTF-8 "); // Import the preceding characters into the Array $ Zhongwenku = array (); For ($ I = 0; $ I <$ zhongwenku_size; $ I ++) { $ Zhongwenku [$ I] = mb_substr ($ str, $ I, 1, "UTF-8 "); } $ Result = ""; // Four characters to be written to the image For ($ I = 0; $ I <4; $ I ++) { Switch (rand (0, 1 )) { Case 0: $ Result. = $ zhongwenku [rand (0, $ zhongwenku_size-1)]; Break; Case 1: $ Result. = dechex (rand (0, 15 )); Break; } } $ _ SESSION ["check"] = $ result; // Create a true color image with a width of 100 and a height of 30 $ Img = imagecreatetruecolor (100, 30 ); // Assign the background color $ Bg = imagecolorallocate ($ img, 0, 0 ); // Assign text color $ Te = imagecolorallocate ($ img, 255,255,255 ); // Write a string on the Image // Imagestring ($ img, rand (), $ result, $ te ); // Write a special font Based on the loaded font on the Image Imagettftext ($ img, 13, rand (2, 9), 20, 20, $ 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 a line Imageline ($ img, 0, rand (0, 20), rand (70,100), rand (0, 20), $ te ); } $ T = imagecolorallocate ($ img, rand (0,255), rand (0,255), rand (0,255 )); // Add noise to the image For ($ I = 0; I I <200; $ I ++) { Imagesetpixel ($ img, rand (1,100), rand (1, 30), $ t ); } // Send the http header to specify that the sent image is jpeg. Header ("Content-type: image/jpeg "); // Output jpeg image to the browser Imagejpeg ($ img ); ?> |