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