PHP overall drawing function-draw a simple half-width English number for drawing characters ~~

Source: Internet
Author: User
Tags transparent color
I have read two articles over the PHP site over the past two days. Article First, "using PHP to implement the verification code function" and "using the dot method in PHP to" Draw "Chinese" suddenly aroused great interest in the PHP drawing function.
PHP's drawing function is much more powerful and simple than ASP, as I personally think.

PHP drawing requires the installation of the GD library first, and the GD library is more than 1.6 and does not support generating GIF images. Generally, php4.0 and above all come with the GD library. For the software environment required for drawing, if it is not the focus of this article, you will not be tired of it. You can refer to other materials.

1. Start to draw English letters and numbers

Header ("Content-Type: image/GIF"); // HTTP header, indicating the meaning of the image
$ String = "test1234"; // string to be drawn
$ Im = imagecreate (100,100); // create a 100*100 canvas. If you have used the drawing software, you should be familiar with the word.
$ Black = imagecolorallocate ($ im, 0, 0, 0); // background color of the canvas
$ White = imagecolorallocate ($ im, 255,255,255); // set white
$ Gray = imagecolorallocate ($ im, 200,200,200); // set gray
Imagestring ($ im, 5, 10, 30, $ string, $ gray); // draw gray characters on the IM canvas (10, 30)

// Add interference pixel points

For ($ I = 1; $ I
For ($ j = 1; $ J
Imagesetpixel ($ im, Rand () % 100, Rand () % 100, $ white );
}
}
Imagepng ($ IM); // output the image in PNG format
Imagedestroy ($ IM); // clear the image memory resources

This is just an introduction to drawing, familiar with some basic functions of drawing.
ProgramIt runs normally on my computer.
For example, you can change $ string to a random number. :) It is also a simple verification code.

Imagecolortransparent this function is used to set the transparent color, very useful :) very good Oh ~~

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.