[英]Fit the text into image PHP GD
Helllo,使用GD,我正在通過$ text創建png圖像。 $ text是腳本生成的,可能需要幾行。 所以,這是我的代碼:
$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函數檢查邊緣: http : //www.php.net/manual/zh/function.imagettfbbox.php或在文本周圍添加邊框。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.