SoFunction
Updated on 2025-03-10

PHP method to obtain a piece of text to display the width and height of the dot matrix

PHP method to obtain a piece of text to display the width and height of the dot matrix

Updated: March 12, 2015 15:30:44 Author: Jianke
This article mainly introduces the method of PHP to obtain a piece of text to display the width and height of dot matrix, which involves the usage of imagettfbbox function and the skills of php to operate ttf text. It has certain reference value. Friends who need it can refer to it.

This article describes how PHP obtains a piece of text to display the width and height of the dot matrix. Share it for your reference. The details are as follows:

define("F_SIZE", 8);
define("F_FONT", "");
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;
}

I hope this article will be helpful to everyone's PHP programming.

  • PHP
  • Get
  • text
  • lattice

Related Articles

  • How to list 100 100 entries of data into Mysql database (PHP)

    This article mainly introduces how to divide 100 million data into Mysql database when the data volume soars. Friends who need it can refer to it
    2015-07-07
  • php empty, isset, is_null judgment comparison (differences and similarities)

    When developing php, I believe that when using the functions: empty, isset, is_null, I encountered some problems. It even brings some security risks to your own programs. Many times, for isset, empty, I think it is almost the same. Therefore, when developing, I didn’t pay attention to it. When a period of process judgment occurs, a bug will occur.
    2010-10-10
  • Manual configuration and usage instructions for XDebug under Windows

    XDebug is a php code debugging tool, which is of great help to programmers to debug programs. Let’s briefly talk about the configuration of XDebug under Windows.
    2010-07-07
  • PHP method to calculate the number of days difference between two dates

    This article mainly introduces the method of php calculating the number of days between two dates. It analyzes the skills of php operating dates in an example. Friends who need it can refer to it.
    2015-03-03
  • Summary of PHP code optimization skills

    When writing programs, we want to minimize the resource usage of our programs, run faster and have less code. PHP's unique syntax mixes C, Java, Perl and PHP's innovative syntax, which can execute dynamic web pages faster than CGI or Perl. PHP embeds programs into HTML documents for execution, and the execution efficiency is much higher than that of CGI that completely generates HTML tags.
    2015-09-09
  • PHP extends Memcache distributed deployment solution

    Although memcached is called a "distributed" cache server, the server side does not have a "distributed" function. The server side only includes memory storage function, and its implementation is very simple. As for the distributed memcached, it is completely implemented by the client library. This distribution is the biggest feature of memcached.
    2015-12-12
  • Analysis of the method of simply implementing singleton design pattern by php

    This article mainly introduces the method of simply implementing single-state design patterns in PHP, and simply analyzes the composition, implementation and usage methods of single-state design patterns. Friends who need it can refer to it
    2017-07-07
  • PHP realizes the conversion between Gregorian dates and lunar dates

    This article mainly introduces the relevant information on PHP to convert Gregorian dates and lunar dates. I hope that you can help you through this article. Friends who need it can refer to it.
    2017-09-09
  • Verification code applet based on php implementation

    This article mainly introduces the specific implementation methods of the verification code applet based on php implementation, and has made detailed annotations, which are conducive to understanding and learning. Friends who need it, let’s take a look.
    2016-12-12
  • Configure nginx+php environment in Windows platform

    Compared with Linux, it is much easier to configure the web environment for Windows, whether it is a one-click installation package or an independent configuration. This time, it is about using NGINX as the local test environment for the web.
    2015-12-12

Latest Comments