我已经创建了一些功能来为用户生成化身,但是中间不能设置一些字母。
这是图像的外观
和代码
$font = 'arial.ttf';
$font_size = '120';
$angle = '0';
$text = 'M';
// Create the image
$im = imagecreatetruecolor(200,240);
$bg = imagecolorallocate($im, $bgColor[0],$bgColor[1],$bgColor[2]);
$white = imagecolorallocate($im, 255, 255,255);
imagefilledrectangle($im, 0, 0, 200, 240, $bg);
$text_box = imagettfbbox($font_size,$angle,$font,$text);
$text_width = $text_box[2]-$text_box[0];
$text_height = $text_box[7]-$text_box[1];
$x = 100 - ($text_width/2);
$y = 120 - ($text_height/2);
// Add the text
imagettftext($im, $font_size, $angle, $x, $y, $white, $font, $text);
不确定问题出在哪里,也许imagettfbbox
无法正确读取字体大小?
此外,我试图在StackOverflow上找到解决方案,但不能