引用 https://blog.csdn.net/fanyilong_v5/article/details/50700578
引用 https://blog.csdn.net/lizhenjian521/article/details/51038547
感谢两位博主
当我们在使用imggettftext 函数的时候会遇到这个问题
imagettftext(): any2eucjp(): invalid code in input string
一切都没有错 这个是php的一个bug
https://bugs.php.net/bug.php?id=42218
原因 编译php的时候 --enable-gd-jis-conv 开启这个选项
解决办法(一)重新编译 php 取消 --enable-gd-jis-conv 这个参数
解决办法(二)对字符串通过to_entities处理
function to_entities($string){ $len = strlen($string); $buf = ""; for($i = 0; $i < $len; $i++){ if (ord($string[$i]) <= 127){ $buf .= $string[$i]; } else if (ord ($string[$i]) <192){ //unexpected 2nd, 3rd or 4th byte $buf .= "�"; } else if (ord ($string[$i]) <224){ //first byte of 2-byte seq $buf .= sprintf("&#%d;", ((ord($string[$i + 0]) & 31) << 6) + (ord($string[$i + 1]) & 63) ); $i += 1; } else if (ord ($string[$i]) <240){ //first byte of 3-byte seq $buf .= sprintf("&#%d;", ((ord($string[$i + 0]) & 15) << 12) + ((ord($string[$i + 1]) & 63) << 6) + (ord($string[$i + 2]) & 63) ); $i += 2; } else { //first byte of 4-byte seq $buf .= sprintf("&#%d;", ((ord($string[$i + 0]) & 7) << 18) + ((ord($string[$i + 1]) & 63) << 12) + ((ord($string[$i + 2]) & 63) << 6) + (ord($string[$i + 3]) & 63) ); $i += 3; } } return $buf; } imagettftext($im, 11, 0, 5, 11, $black, $font, to_entities($text));