PHP image output problems-php Tutorial

Source: Internet
Author: User
PHP image output: the code is as follows,

// Step 1: Set the MIME type and output format
Header ("Content-Type: image/png ;");
For ($ I = 0; $ I <4; $ I ++)
{
$ Nmsg. = dechex (mt_rand (0, 15 ));
}
Echo $ nmsg;
// Create a blank area in step 2
$ Im = imagecreatetruecolor (200,200 );
// Create imagecolorallocate in step 3 to fill the image color
$ Blue = imagecolorallocate (USD im, 0,102,255 );
// Fill the blue color with the background in step 4
Imagefill ($ im, 0, 0, $ blue );
// Fill in the text in step 5
$ White = imagecolorallocate ($ im, 255,255,255 );
Imagestring ($ im, 5, 80, 80, $ nmsg, $ white );
// Step 6 first, let's take a look at the effect.
Imagepng ($ im );
// Destroy and keep the memory
Imagedestroy ($ im );
?>


Reply to discussion (solution)



The error is:

There is a problem with the FOR loop. I output a verification code and put $ nmsg. = dechex (mt_rand. if this parameter is removed, a verification code is displayed, and an error is returned.

Declare the $ nmsg variable before the for loop:

$nmsg = "";

/Step 1: Set the MIME type and output format
Header ("Content-Type: image/png ;");
$ Nmsg = '';
For ($ I = 0; $ I <4; $ I ++)
{
$ Nmsg. = dechex (mt_rand (0, 15 ));
}
// Echo $ nmsg;


In this way, you can.

 

Thank you!

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.