Php image creation steps, php image steps

Source: Internet
Author: User

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

 

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.