
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get Pixel Width of a Character in PHP Using imagefontwidth
imagefontwidth() is an inbuilt function in PHP that is used to get the pixel width of a character in the specified font.
Syntax
int imagefontwidth(int $font)
Parameters
imagefontwidth() takes only one parameter, $font. It holds the font value. The $font values can be 1, 2, 3, 4, and 5 for the built-in fonts or it can be used by using imageloadfont() function for custom fonts.
Return Values
imagefontwidth() returns the pixel width of the font.
Example 1
<?php // font width values can be changed from 1 to 5. echo 'Font width: '.imagefontwidth(3); ?>
Output
Font width: 7
Example 2
<?php // Set the font width from 1 to 5 echo 'Font width for the font value 1 is' .imagefontwidth(1).'<br>'; echo 'Font width for the font value 2 is' .imagefontwidth(2).'<br>'; echo 'Font width for the font value 3 is' .imagefontwidth(3).'<br>'; echo 'Font width for the font value 4 is' .imagefontwidth(4).'<br>'; echo 'Font width for the font value 5 is' .imagefontwidth(5).'<br>'; ?>
Output
Font width for the font value 1 is 5 Font width for the font value 2 is 6 Font width for the font value 3 is 7 Font width for the font value 4 is 8 Font width for the font value 5 is 9
Advertisements