Php image creation steps, php image steps
Php image processing is the most common in the verification code. The following describes how to create an image using php.
Brief description:PHP is not limited to creating HTML output. It can also create and process GIF files., PNG (recommended), JPEG, WBMPAnd XPMImages in multiple formats. More conveniently, PHP can directly output the image data stream to the browser. To use the image processing function in PHP, you need to use GD togetherLibrary to compile PHP. GDLibraries and PHP may need other libraries, depending on the image format you want to process.
You can use the image function in PHP to obtain the image in the following format: JPEG, GIF, PNG (recommended: images created without losing the needle), SWF, TIFFAnd.
Step Description: For details about the function, refer to the php manual.
1 <? Php 2 3 // 1: Set the header to inform the browser of the MIME type 4 header ("Content-type: image/png") to be generated ");
5 // Second: Create a canvas. Subsequent operations will be based on this canvas area 6 $ codew = 100; 7 $ codeh = 60; 8 $ codeimg = imagecreatetruecolor ($ codew, $ codeh); 9 10 // obtain canvas color 11 $ red = imagecolorallocate ($ codeimg, 255, 0, 0); 12 $ white = imagecolorallocate ($ codeimg, 255,255,255 ); 13 $ green = imagecolorallocate ($ codeimg, 75,222, 26); 14 // third: Fill the canvas background color 15 imagefill ($ codeimg, 0, 0, $ red ); 16 17 // Fourth: draw lines + fill text... 18 imageline ($ codeimg, 0, 00, 30, 60, $ wh Ite); 19 imageline ($ codeimg, 0, 00, 50, 60, $ white); 20 imageline ($ codeimg, 0, 00, 80, 60, $ white ); 21 22 // fill in the text 23 imagestring ($ codeimg, 10, 30, 30, "qwe4", $ green); 24 25 // Fifth: output The created canvas 26 imagepng ($ codeimg); 27 28 // Sixth: Destroy canvas 29 imagedestroy ($ codeimg); 30 31?>
View results