PHP Image output Problem,

Source: Internet
Author: User
Code as follows,

The first step is to set the MIME type, output format
Header ("content-type:image/png;");
for ($i =0; $i <4; $i + +)
{
$nmsg. =dechex (Mt_rand (0,15));
}
Echo $nmsg;
Second step to create a blank area
$im =imagecreatetruecolor (200,200);
Step three create imagecolorallocate for image fill color
$blue =imagecolorallocate ($im, 0,102,255);
The fourth step fills the blue with the background
Imagefill ($im, 0,0, $blue);
Fifth Step fill text
$white =imagecolorallocate ($im, 255,255,255);
Imagestring ($im, 5,80,80, $nmsg, $white);
The sixth step first output look at the effect
Imagepng ($im);
Destroy, keep the memory
Imagedestroy ($im);
?>


Reply to discussion (solution)



This is the mistake.

Mainly for the For loop that has a problem, I output a verification code, put $nmsg. =dechex (Mt_rand (0,15)); remove it, it will show a verification code, plus the error

The For loop declares the $NMSG variable before:

$nmsg = "";

/First Step setting MIME type, output format
Header ("content-type:image/png;");
$nmsg = ";
for ($i =0; $i <4; $i + +)
{
$nmsg. =dechex (Mt_rand (0,15));
}
Echo $nmsg;


That's all you can do.

 
  

Thank you, great God!

  • 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.