Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用imagettftext()设置不同的字体大小_Php_Font Size_Imagettftext - Fatal编程技术网

Php 使用imagettftext()设置不同的字体大小

Php 使用imagettftext()设置不同的字体大小,php,font-size,imagettftext,Php,Font Size,Imagettftext,是否可以在一个imagettftext()内的图像上设置不同的font sizes 我已设法在图像上输出所需的文本。现在,我想用更大的字体大小显示$subheadliner\u thu\u 1。我不想把它放在一个新的imagettftext(),因为文本的长度将来可能会改变。因此,设置的坐标不应用于$undercard\u thu\u 4 这是我的密码: <?php header('Content-type: image/jpeg'); $jpg_image = imagecrea

是否可以在一个
imagettftext()
内的图像上设置不同的
font size
s

我已设法在图像上输出所需的文本。现在,我想用更大的
字体大小显示
$subheadliner\u thu\u 1
。我不想把它放在一个新的
imagettftext()
,因为文本的长度将来可能会改变。因此,设置的坐标不应用于
$undercard\u thu\u 4

这是我的密码:

<?php
  header('Content-type: image/jpeg');
  $jpg_image = imagecreatefromjpeg('img/pkp-empty.jpg');
  $white = imagecolorallocate($jpg_image, 255, 255, 255);
  $font_path = 'fonts/calibri.ttf';

  $undercard_thu_1 = "amelie lens";
  $undercard_thu_1 = strtoupper($undercard_thu_1);
  $undercard_thu_2 = "beautifull swimmers";
  $undercard_thu_2 = strtoupper($undercard_thu_2);
  $undercard_thu_4 = "cypress hill";
  $undercard_thu_4 = strtoupper($undercard_thu_4);
  $subheadliner_thu_1 = "chance the rapper";
  $subheadliner_thu_1 = strtoupper($subheadliner_thu_1);

  $lineup_upper1 = $undercard_thu_1 . ' • ' . $undercard_thu_2;
  $lineup1 = wordwrap($lineup_upper1, 60, "\n", false);

  $lineup_upper2 = $subheadliner_thu_1 . ' • ' . $undercard_thu_4;
  $lineup2 = wordwrap($lineup_upper2, 60, "\n", false);

  imagettftext($jpg_image, 25, 0, 295, 532, $white, $font_path, $lineup1);
  imagettftext($jpg_image, 25, 0, 72, 579, $white, $font_path, $lineup2);

  imagejpeg($jpg_image);
  imagedestroy($jpg_image);
?>


如果您使用的是固定宽度字体,很容易创建一个可以计算宽度的函数,否则您可能会遇到问题我认为您无法。。。特别是考虑到@delboy1978uk所说的话……我制作了一个PDF文件,还有一些行我必须计算宽度等。看看这里,按住CTRL-F键,将文本调整到特定的宽度,了解如何编码。如果你使用的是固定宽度的字体,很容易创建一个可以计算宽度的函数,否则你可能会有问题我认为你不能。。。特别是考虑到@delboy1978uk所说的话……我制作了一个PDF文件,还有一些行我必须计算宽度等。看看这里,按住CTRL-F键,将文本调整到特定的宽度,了解如何编码。