php imagettftext 行高

标签 php html css

我已经成功地将文本写入我的 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']));

关于php imagettftext 行高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35895010/

相关文章:

php - 比较两个时间戳 Codeigniter

javascript - 检查下拉菜单并动态更改单元格颜色

html - 如何修复 float html div 的布局和大小?

jquery - ASP.NET 赋予 Linklabel 风格

php - Zend 中的查询联合不同

javascript - 这是我的代码,我想添加日期选择器事件,它根据日期给出特定记录

php - 将数据写入html页面

html - 元素与其后的另一个居中元素对齐

javascript - 从 0 到 x 的 CSS 宽度转换导致内容压缩

javascript - 具有可折叠和不可折叠元素的导航栏