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 be created and processed, includingGIF, PNG (recommended), JPEG, WBMP, and 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 compile PHP together with the GD library. The GD library 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 images in the following format:JPEG, GIF, and PNG (recommended: Images Created with no pins left), SWF, TIFF, and MPEG-4.

Step Description: For details about the function, refer to the php manual.

<? Php // first: Set the header to tell the browser the MIME type header ("Content-type: image/png") You want to generate; // Second: Create a canvas, subsequent operations will be based on the canvas area $ codew = 100; $ codeh = 60; $ codeimg = imagecreatetruecolor ($ codew, $ codeh ); // obtain the canvas color $ red = imagecolorallocate ($ codeimg, 255, 0, 0); $ white = imagecolorallocate ($ codeimg, 255,255,255); $ green = imagecolorallocate ($ codeimg, 75,222, 26); // third: Fill the canvas background color imagefill ($ codeimg, 0, 0, $ red); // Fourth: draw lines + fill text... imageline ($ cod Eimg, 0, 00, 30, 60, $ white); imageline ($ codeimg, 0, 00, 50, 60, $ white); imageline ($ codeimg, 0, 00, 80, 60, $ white); // fill in the text imagestring ($ codeimg, 10, 30, 30, "qwe4", $ green); // Fifth: output The created canvas imagepng ($ codeimg); // Sixth: destroy the canvas imagedestroy ($ codeimg);?>

View results

The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!

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.