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