php imagettftext line height


php imagettftext line height

我已经成功地将文本写入我的img并正确定位了它,但是我遇到的问题是增加字体大小会使文本偏离图像。

所以我知道我可以通过简单地增加写入屏幕的文本的行高来实现我想要的外观。我似乎找不到任何关于是否/如何做到这一点的文档。

我的 php 代码

<?php  
  $font = 'font-type.ttf';
  $rImg = ImageCreateFromJPEG( "test.jpg" );
  $color = imagecolorallocate($rImg, 255, 255, 255);
  //create bounding box
  $bbox = imagettfbbox ( 38 , 0 , $font , urldecode($_GET['promo']) );
  //setting the cordinates
  $x = $bbox[0] + (imagesx($rImg) / 2) - ($bbox[4] / 2) + 200;
  $y = $bbox[1] + (imagesy($rImg) / 2) - ($bbox[5] / 2) + 25;
  //write it
  imagettftext($rImg, 38, 0, $x, $y, $color, $font, urldecode($_GET['promo']));
  header('Content-type: image/jpeg');
  imagejpeg($rImg, NULL,100);
  imagedestroy($rImg);
?>

我使用此功能实现了我想要的外观

function ImageTTFTextWithTracking($im, $size, $angle, $t, $x, $y, $color, $font, $text) {
$numchar = strlen($text);
for($i = 0; $i < $numchar; $i++) {
    # Assign character
    $char[$i] = substr($text, $i, 1);
    # Write character
    imagettftext($im, $size, $angle, ($x + $w + ($i * $t)), $y, $color, $font, $char[$i]);
    # Get width of character
    $width = imagettfbbox($size, $angle, $font, $char[$i]);
    $w = $w + $width[2];
}
}
ImageTTFTextWithTracking($rImg, 48, 0, 10, $x, $y, $colorWhite, $font, urldecode($_GET['code']));