PHP 5.0.1 GD2.0.28 supports creation GIF images [with a picture verification program]

xiaoxiao2021-03-06  139

PHP 5.0.1 in GD2.0.28 supports creation GIF images, I tested it, it is true. Attached to a picture verification code I wrote, I packed it into a class, and it can be used in function. Change yourself, huh, huh.

/ ** * @Author Shenkong * @version $ ID * @Package SPB forum system * @copyright deep space (SHENKONG) Copyright, anyone modified and used must keep this copyright information * / Class CheckImage {public $ bgLength; public $ bgWidth; public $ bgColor; public $ fontSize; public $ fontType; public $ length; public $ image; public $ string; function __construct ($ info) {$ this-> bgLength = $ info [ " Bglength "]; $ this-> bgwidth = $ info [" bgwidth "]; $ this-> fontsize = $ info [" fontsize "]; $ this-> fonttype = $ info [" fonttype "]; $ this-> Length = $ info ["Length"]; $ this-> Image = $ this-> CreateImage (); // $ black = imagecolorallocate ($ this-> image, 0x00, 0x00, 0x00); $ white = imagecolorallocate ($ This-> image, 0xff, 0xff, 0xff); ImageFilledRectangle ($ this-> Image, 0, 0, $ this-> bglength, $ this-> bgwidth, $ white); $ this-> MixImage (500, 10) ; $ this-> Write (); $ this-> MixImage (50, 5); // Set white is transparent imagecolortransparent ($ this-> image, $ white); Header ("Content-Type: Image / GIF"); imagegif ($ this-> image);} function createImage () {return imagecreatetruecolor ($ this-> bgLength, $ this-> bgWidth);} function randColor () {return imagecolorallocate ($ this-> image, mt_rand (0, 200), MT_RAND (0, 100), MT_RAND (0, 150));

PUBLIC FUNCTION WRITE () {$ Str = MD5 (MT_RAND ()); $ Str = STRTOUPPER ($ STR); $ Str = STR_REPLACE (Array ("I", "1", "5", "S", " 4 "," A "," 8 "," B "," 0 "," D ")," ", $ STR); $ Str = Substr ($ Str, 0, $ THIS-> Length); $ THIS -> String = $ Str; $ w = ($ this-> bglength - ($ this-> length - 1) * 3) / $ this-> length; for ($ i = 0; $ i <$-> Length; $ i ) {imagetftext ($ this-> Image, $ this-> fontsize, mt_rand (-20, 20), MT_RAND ($ I * $ W $ I * 3, ($ I 1) * $ w $ I * 3 - $ THIS-> FONTSIZE), MT_RAND ($ this-> Fontsize, $ THIS-> BGWIDTH - $ this-> bgwidth / 10), $ this-> randcolor (), $ this-> fonttype, Substr ($ STR, $ I, 1));}}} Function setString () {Require_once "session.class.php"; $ s = new session (); $ s-> setpath ();} Function MixImage ($ NUM = 500, $ fontsize = 10) {for ($ I = 0; $ i <$ NUM; $ I ) {ImagetTFText ($ this-> Image, $ fontsize, mt_rand (-180, 180), MT_Rand (1, $ this-> bglength), MT_RAND (1, $ this-> bgwidth), ImageColoralLocate ($ this-> Image, MT_RAND (150, 255), MT_RAND (150, 255)), $ this-> fonttype, "|");}}}

转载请注明原文地址:https://www.9cbs.com/read-127290.html

New Post(0)