简体   繁体   English

自定义字体的字体大小

[英]Font size with custom font

So I've got my image and even some text on it. 这样我就得到了我的图像,甚至还有一些文字。 I tried to load a font and it worked, but how could I select the font size? 我尝试加载字体并且可以正常工作,但是如何选择字体大小? The code for the text I have is below. 我的文字代码如下。

imagestring($img, imageloadfont('dist/font.ttf'), 20, 20, 'Testing!', imagecolorallocate($img, 0, 0, 0));

Before, I could set the font size in the second attribute, but now I've got a remote font there. 以前,我可以在第二个属性中设置字体大小,但是现在那里有一个远程字体。

I would recommend you to use imagettftext() if you wish to write text to your image using a truetype font. 如果您希望使用truetype字体将文本写入图像,则建议您使用imagettftext()

imagettftext ( 
   resource $im ,
   int $size ,
   int $angle ,
   int $x ,
   int $y ,
   int $col ,
   string $fontfile ,
   string $text 
)

This allows you to set the font size specifically. 这使您可以专门设置字体大小。 Should do for your purposes. 应该为您的目的。

Note 注意

Depending on your version of the GD library, you need to specify the font size in either pixels or points. 根据GD库的版本,您需要以像素或磅为单位指定字体大小。

From the Docs: 从文档中:

The font size. 字体大小。 Depending on your version of GD, this should be specified as the pixel size (GD1) or point size (GD2). 根据您的GD版本,应将其指定为像素大小(GD1)或点大小(GD2)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM