Home >Backend Development >PHP Tutorial >How to calculate the pixel height and width of the font size set by functions like imagettftext imagestring in the gd function library? ?

How to calculate the pixel height and width of the font size set by functions like imagettftext imagestring in the gd function library? ?

WBOY
WBOYOriginal
2016-07-06 13:52:311439browse

<code>怎么计算 imagestring($source,$font_size,$x,$y,$string,$color) 中$font_size(除去预置的1-5)设置的字体大小所对应的像素值??
这边的$font_size(除去预置的1-5)设置的字体大小的单位是什么?? 即若是$font_size=15,那是指字体大小为15px??</code>

Reply content:

<code>怎么计算 imagestring($source,$font_size,$x,$y,$string,$color) 中$font_size(除去预置的1-5)设置的字体大小所对应的像素值??
这边的$font_size(除去预置的1-5)设置的字体大小的单位是什么?? 即若是$font_size=15,那是指字体大小为15px??</code>

You can use the imagettfbbox function to calculate the height and width of the TTF font string, and use imagettftext to write the image

http://php.net/manual/zh/function.imagettfbbox.php
http://php.net/manual/zh/function.imagettftext.php

Supplement:
The second parameter of the imagestring function you mentioned is not fontsize but font, which are the 5 fonts pre-made by GD. The size is and cannot be modified, if you want to use additional fonts, you need to use the imageloadfont function to load them. What is loaded is not a ttf font, so the effect you expect will not work if you use these two functions

http://php.net/manual/zh/function.imagestring.php
http://php.net/manual/zh/function.imageloadfont.php

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn