Ubuntu PHP server, captcha picture does not show characters, what's going on
Ubuntu PHP server, captcha picture does not display characters, what's going on?
There is a picture generated, that is, no character display. Is the character set wrong? Where is the setting?
Share to:
------Solution--------------------
References:
Quote: References:
Code to check it out.
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));
$tmpC 0=mt_rand (100,255);
$tmpC 1=mt_rand (100,255);
$tmpC 2=mt_rand (100,255);
$buttum _c = imagecolorallocate ($im, $tmpC 0, $tmpC 1, $tmpC 2);
Imagefill ($im, $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, $text _c, $font, $tmp);
}
$distortion _im = Imagecreatetruecolor ($im _x, $im _y);
Imagefill ($distortion _im, $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) * ) >=0) {
Imagesetpixel ($distortion _im, (int) ($i +10+sin ($j/$im _y*2*m_pi-m_pi*0.1), $j, $rgb);
}
}
}
adding interfering pixels;
$count = number of 160;//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);
$rand 1 = mt_rand (15,25);
$rand 2 = Mt_rand (5,10);
for ($yy = $rand; $yy <=+ $rand +2; $yy + +) {
for ($px =-80; $px <=80; $px = $px +0.1)
{
$x = $px/$rand 1;
if ($x!=0)
{
$y =sin ($x);
}
$py = $y * $rand 2;
Imagesetpixel ($distortion _im, $px +80, $py + $yy, $text _c);
}
}
Set the file header;
Header ("Content-type:image/jpeg");
Export the image to a browser or file in PNG format;
Imagepng ($distortion _im);
Destroys an image, releasing the memory associated with image;
Imagedestroy ($distortion _im);
Imagedestroy ($im);
}
function Make_rand ($length = "32") {//Captcha text generation functions
$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 ();//storing random numbers in session
$_session[' Helloweba_gg ']=strtolower ($checkcode);
Getauthimage ($checkcode);
?>
The Windows Server can. It's Ubuntu, No.
Check your font file path.
------Solution--------------------
You put 62 lines of Header ("Content-type:image/jpeg"); Comment out and you'll see the error message.
TTF is a font file for Windows, you need to install the support library