Php 将文本放入图像中
Helllo,我正在使用GD从$text创建一个png图像。$text是脚本生成的,可能需要几行。 这是我的代码:Php 将文本放入图像中,php,Php,Helllo,我正在使用GD从$text创建一个png图像。$text是脚本生成的,可能需要几行。 这是我的代码: $imageWidth=400; $imageHeight=100; $logoimg = imagecreatetruecolor($imageWidth, $imageHeight); //create Image imagealphablending($logoimg, false); imagesavealpha($logoimg, true); $col=imageco
$imageWidth=400;
$imageHeight=100;
$logoimg = imagecreatetruecolor($imageWidth, $imageHeight); //create Image
imagealphablending($logoimg, false);
imagesavealpha($logoimg, true);
$col=imagecolorallocatealpha($logoimg,255,255,255,127);
imagefill($logoimg, 0, 0, $col);
$white = imagecolorallocate($logoimg, 0, 0, 0);
$font = "TNR.ttf"; //font path
$fontsize=14;
$x=10;
$y=20;
$angle=0;
imagettftext($logoimg, $fontsize,$angle , $x, $y, $white, $font, $text);
$target="temp.png"; //path of target
imagepng($logoimg,$target);
我的问题是,有时文本会被剪切几个像素。以下是一个例子:
所以,问题是,我如何才能使文本适合图像?谢谢你抽出时间 在写入文本之前,可以使用imagettfbox函数检查边缘: 或者,在文本周围添加边框