PHP获取一段文本显示点阵宽度和高度的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了PHP获取一段文本显示点阵宽度和高度的方法。分享给大家供大家参考。具体如下:

define("F_SIZE", 8);
define("F_FONT", "arial.ttf");
function get_bbox($text){
  return imagettfbbox(F_SIZE, 0, F_FONT, $text);
}
function text_height ($text) {
  $box = get_bbox($text);
  $height = $box[3] - $box[5];
  return $height;
}
function text_width ($text) {
  $box = get_bbox($text);
  $width = $box[4] - $box[6];
  return $width;
}

希望本文所述对大家的php程序设计有所帮助。

相关文章

PHP实现多文件上传的方法

本文实例讲述了PHP实现多文件上传的方法。分享给大家供大家参考。具体实现方法如下: <?php define('ROOT','D:/Program Files/www/...

PHP获取文件扩展名的4种方法

本文实例讲述了PHP获取文件扩展名的4种方法。分享给大家供大家参考,具体如下: $filename="123.jpg"; //方法一: function get_ext($file_...

解决PHP 7编译安装错误:cannot stat ‘phar.phar’: No such file or directory

解决PHP 7编译安装错误:cannot stat ‘phar.phar’: No such file or directory

前言 最近因为工作需要要使用PHP 7,所以从网上找教程进行安装, 结果编译没问题, 安装的时候报了错误。 错误如下 cp -pR -f phar.phar /usr/local/p...

asp函数split()对应php函数explode()

<?php //利用 explode 函数分割字符串到数组 $source = "hello1,hello2,hello3,hello4,hello5";//按逗号分离...

php foreach、while性能比较

foreach是对数组副本进行操作(通过拷贝数组),而while则通过移动数组内部指标进行操作,一般逻辑下认为,while应该比foreach快(因为foreach在开始执行的时候首先把...