PHP method to get text display dot matrix width and height

墨辰丷
Release: 2023-03-31 19:38:02
Original
1469 people have browsed it

This article mainly introduces the method of PHP to obtain the width and height of a text display lattice, involving the usage of the imagettfbbox function and the skills of PHP operating ttf text. It has certain reference value. Friends in need can refer to it

The example in this article describes how PHP obtains the width and height of a text display dot matrix. The details are as follows:

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;
}
Copy after login

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

php methods for string function operations

php object instantiation and cloning methods

How to read the lattice data of Chinese characters in PHP

The above is the detailed content of PHP method to get text display dot matrix width and height. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!