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.

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.

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).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top