gpt4 book ai didi

php imagettftext 行高

转载 作者:行者123 更新时间:2023-11-28 06:15:55 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com