On the PHP server of ubuntu, no characters are displayed in the verification code image.

Source: Internet
Author: User
On the PHP server of ubuntu, the verification code image does not display characters. what is the problem? on the PHP server of ubuntu & nbsp;, the verification code image does not display characters. what is the problem? If an image is generated, no characters are displayed. Is it a character set error? Where to set? On the PHP server of ubuntu, the verification code image does not display characters. what is the problem?
On the PHP server of ubuntu, the verification code image does not display characters. what is the problem?
If an image is generated, no characters are displayed. Is it a character set error? Where to set? Share:
------ Solution --------------------
Reference:
Quote: reference:

After the code is posted, let's take a look.

   Function getAuthImage ($ text ){
$ Im_x = 160;
$ Im_y = 40;
$ Im = imagecreatetruecolor ($ im_x, $ im_y );
$ Text_c = ImageColorAllocate ($ im, mt_rand (0,100), mt_rand (0,100), mt_rand (0,100 ));
$ TmpC0 = mt_rand (100,255 );
$ TmpC1 = mt_rand (100,255 );
$ TmpC2 = mt_rand (100,255 );
$ Buttum_c = ImageColorAllocate ($ im, $ tmpC0, $ tmpC1, $ tmpC2 );
Imagefill ($ im, 16, 13, $ buttum_c );

$ Font = 't1. ttf ';

For ($ I = 0; $ I {
$ Tmp = substr ($ text, $ I, 1 );
$ Array = array (-1, 1 );
$ P = array_rand ($ array );
$ An = $ array [$ p] * mt_rand (1, 10); // angle
$ Size = 28;
Imagettftext ($ im, $ size, $ an, 15 + $ I * $ size, 35, $ text_c, $ font, $ tmp );
}


$ Distortion_im = imagecreatetruecolor ($ im_x, $ im_y );

Imagefill ($ distortion_im, 16, 13, $ buttum_c );
For ($ I = 0; $ I <$ im_x; $ I ++ ){
For ($ j = 0; $ j <$ im_y; $ j ++ ){
$ Rgb = imagecolorat ($ im, $ I, $ j );
If (int) ($ I + 20 + sin ($ j/$ im_y * 2 * M_PI) * 10) <= imagesx ($ distortion_im) & (int) ($ I + 20 + sin ($ j/$ im_y * 2 * M_PI) * 10)> = 0 ){
Imagesetpixel ($ distortion_im, (int) ($ I + 10 + sin ($ j/$ im_y * 2 * M_PI-M_PI * 0.1) * 4), $ j, $ rgb );
}
}
}
// Add interference pixels;
$ Count = 160; // Number of interfering pixels
For ($ I = 0; $ I <$ count; $ I ++ ){
$ Randcolor = ImageColorallocate ($ distortion_im, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagesetpixel ($ distortion_im, mt_rand () % $ im_x, mt_rand () % $ im_y, $ randcolor );
}

$ Rand = mt_rand (5, 30 );
$ Rand1 = mt_rand (15, 25 );
$ Rand2 = mt_rand (5, 10 );
For ($ yy = $ rand; $ yy <= + $ rand + 2; $ yy ++ ){
For ($ px =-80; $ px <= 80; $ px = $ px + 0.1)
{
$ X = $ px/$ rand1;
If ($ x! = 0)
{
$ Y = sin ($ x );
}
$ Py = $ y * $ rand2;

Imagesetpixel ($ distortion_im, $ px + 80, $ py + $ yy, $ text_c );
}
}

// Set the file header;
Header ("Content-type: image/JPEG ");

// Output the image to a browser or file in PNG format;
ImagePNG ($ distortion_im );

// Destroy an image and release the memory associated with the image;
ImageDestroy ($ distortion_im );
ImageDestroy ($ im );
}

Function make_rand ($ length = "32") {// verification code text generation function
$ Str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
$ Result = "";
For ($ I = 0; $ I <$ length; $ I ++ ){
$ Num [$ I] = rand (0, 25 );
$ Result. = $ str [$ num [$ I];
}
Return $ result;
}


// Output call
$ Checkcode = make_rand (4 );
Session_start (); // Save the random number to the session.
$ _ SESSION ['helloweba _ GG'] = strtolower ($ checkcode );
GetAuthImage ($ checkcode );
?>





Windows Server can. ubuntu cannot.


Check the path of your font file.
------ Solution --------------------
You can comment out 62 rows of Header ("Content-type: image/JPEG") to see the error message.
Ttf is a windows font file. you need to install the support Library

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.