If code GD generates an image $ im: {code...}, then the question is, how can I store this image on my server? For example, code GD generates an image $ im:
Public function generateCode () {$ w = 50; $ h = 20; $ this-> load-> config ('common '); $ common_config = $ this-> config-> item ('common'); $ pic_verify_code = $ common_config ['pic _ verify_code ']; $ code = func :: getRandCode ($ pic_verify_code); // create an image and define the color value $ im = imagecreate ($ w, $ h); $ black = imagecolorallocate ($ im, 90, 90 ); $ gray = imagecolorallocate ($ im, 189,252,201); $ bgcolor = imagecolorallocate ($ im, 255,255,255); // fill the background imagefill ($ im, 0, 0, $ gray ); // draw the border imagerectangle ($ im, 0, 0, $ W-1, $ h-1, $ black); // draw two dotted lines randomly, interference function $ style = array ($ black, $ black, $ gray ); imagesetstyle ($ im, $ style); $ y1 = rand (0, $ h); $ y2 = rand (0, $ h); $ y3 = rand (0, $ h); $ y4 = rand (0, $ h); imageline ($ im, 0, $ y1, $ w, $ y3, IMG_COLOR_STYLED); imageline ($ im, 0, $ y2, $ w, $ y4, IMG_COLOR_STYLED); // randomly generate a large number of black spots on the canvas, which can interfere with ($ I = 0; $ I <80; $ I ++) {imagesetpixel ($ im, rand (0, $ w), rand (0, $ h), $ black );} // randomly display numbers on the canvas. The horizontal spacing and position of characters are randomly generated according to a certain fluctuation range $ strx = rand (3, 8); for ($ I = 0; $ I <$ pic_verify_code; $ I ++) {$ strpos = rand (1, 6); imagestring ($ im, 5, $ strx, $ strpos, substr ($ code, $ I, 1), $ black); $ strx + = rand (8, 12 );}
So the question is, how can I store this image on my server?
Reply content:
For example, code GD generates an image $ im:
Public function generateCode () {$ w = 50; $ h = 20; $ this-> load-> config ('common '); $ common_config = $ this-> config-> item ('common'); $ pic_verify_code = $ common_config ['pic _ verify_code ']; $ code = func :: getRandCode ($ pic_verify_code); // create an image and define the color value $ im = imagecreate ($ w, $ h); $ black = imagecolorallocate ($ im, 90, 90 ); $ gray = imagecolorallocate ($ im, 189,252,201); $ bgcolor = imagecolorallocate ($ im, 255,255,255); // fill the background imagefill ($ im, 0, 0, $ gray ); // draw the border imagerectangle ($ im, 0, 0, $ W-1, $ h-1, $ black); // draw two dotted lines randomly, interference function $ style = array ($ black, $ black, $ gray ); imagesetstyle ($ im, $ style); $ y1 = rand (0, $ h); $ y2 = rand (0, $ h); $ y3 = rand (0, $ h); $ y4 = rand (0, $ h); imageline ($ im, 0, $ y1, $ w, $ y3, IMG_COLOR_STYLED); imageline ($ im, 0, $ y2, $ w, $ y4, IMG_COLOR_STYLED); // randomly generate a large number of black spots on the canvas, which can interfere with ($ I = 0; $ I <80; $ I ++) {imagesetpixel ($ im, rand (0, $ w), rand (0, $ h), $ black );} // randomly display numbers on the canvas. The horizontal spacing and position of characters are randomly generated according to a certain fluctuation range $ strx = rand (3, 8); for ($ I = 0; $ I <$ pic_verify_code; $ I ++) {$ strpos = rand (1, 6); imagestring ($ im, 5, $ strx, $ strpos, substr ($ code, $ I, 1), $ black); $ strx + = rand (8, 12 );}
So the question is, how can I store this image on my server?
Write to file, e. fwite ()
imagepng($im,'pic.png');
Simply send the verification code to the client. What should I do to save it;
Xxx. php:
Imagepng ($ im );
Log in there