今天gd发现用中文生产图片的时候乱码。
搜索了一下,说是由于GD库编译时添加了: –enable-gd-jis-conv 的支持( GD: Enable JIS-mapped Japanese font ) , 在phpinfo()里也可以看到:JIS-mapped Japanese Font Support的支持为enable
取消这个日文支持,乱码即可消除。
另外不用重新编译也可以
将字符串转码一次也可以
$str = mb_convert_encoding($str, "html-entities","utf-8" );// <?php session_start(); $im = imagecreatetruecolor(80,30); $bg = imagecolorallocate($im,0,0,0); $te = imagecolorallocate($im,255,255,255); for($i=0;$i<5;$i++) { $te2 = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255)); imageline($im,rand(0,80),0,80,rand(0,30),$te2); } for($i=0;$i<200;$i++) { imagesetpixel($im,rand()%100,rand()%30,$te2); } srand((float) microtime() * 10000000); $input = array("步","步","高","请","转","到","图","像","我","非","常","高","兴"); $rand_keys = array_rand($input, 4); $_SESSION['yzm'] = $t = $input[$rand_keys[0]].$input[$rand_keys[1]].$input[$rand_keys[2]].$input[$rand_keys[3]]; //$t =iconv("GB2312","UTF-8",$t);// $t = mb_convert_encoding($t, "html-entities","utf-8" );// imagettftext($im,12,0,10,20,$te,'simhei.ttf',$t); header("content-type: image/jpeg"); imagejpeg($im); ?>