| 1.qi Enable GD Library GD library provides a series of APIs for working with images, using the GD library to process pictures, or to create images. The GD library on the site is often used to generate thumbnails or to add watermarks to images or generate reports on site data. Session_Start (); The GBK encoded string into the UTF-8 string, the first argument is written GBK because the php file stored in the host encoding is GBK encoded UTF-8 encoding Browser Universal support, strong versatility, this translates into UTF-8 $str = Iconv ("GBK", "Utf-8", "The mortal life of the Green Mountains and monuments open heart will clouds unroll happiness will always accompany you"); if (!is_string ($str) | |!mb_check_encoding ($STR, "Utf-8")) { Exit ("Not a string or not a utf-8"); } $zhongwenku _size; To get the length of a 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 = ""; Four characters to write on a picture 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 picture width 100, Height 30 $img = Imagecreatetruecolor (100, 30); Assigning background colors $BG = imagecolorallocate ($img, 0, 0, 0); Assigning text colors $te = Imagecolorallocate ($img, 255,255,255); Write a string on a picture Imagestring ($img, Rand (3,8), Rand (1,70), Rand (1,10), $result, $te); A special font can be written on a picture based on the loaded font Imagettftext ($IMG, Max, 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 Imageline ($img, 0, rand (0,), rand (70,100), rand (0,), $te); } $t = Imagecolorallocate ($img, rand (0, 255), rand (0, 255), rand (0, 255)); Add noise to a picture for ($i =0; $i <200; $i + +) { Imagesetpixel ($img, rand (1, +), rand (1,), $t); } Send HTTP header information specifies that the JPEG in image is sent this time Header ("Content-type:image/jpeg"); Output JPEG image to browser Imagejpeg ($IMG); ?> |