PHP generates background color picture verification code

Source: Internet
Author: User
Tags image identifier php and php tutorial rand set background

Imagecreatetruecolor () Creates a true color image,
Does not automatically register the first color of the Imagecolorallocate () method as the background color, but must use Imagefill () to populate


Set color

$BG = Imagecolorallocate ($im, 240, 240, 0);/Set Background color
Imagefill ($im, 0,0, $BG);/load Background color
$te = imagecolorallocate ($im, 0, 0, 0);//String color
Add a string to the picture
Imagestring ($im, Rand (3,6), Rand (5,60), Rand (5,15), $rand, $te);
Output picture
Header ("Content-type:image/jpeg");
Imagejpeg ($im);

Imagecreatetruecolor () returns an image identifier representing a black image of the specified size.

According to your PHP and GD version of the function defined or not. For PHP 4.0.6 through 4.1.x This function always exists


For more details please see: PHP tutorial Er/24/php-imagecreatetruecolor.htm ">http://www.111cn.net/phper/24/php-imagecreatetruecolor.htm

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.