


How to calculate the pixel height and width of the font size set by functions like imagettftext imagestring in the gd function library? ?
Jul 06, 2016 pm 01:52 PM
<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

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
