

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to get the pixel width of a character in the specified font using the imagefontwidth() function in PHP?
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
- Related Questions & Answers
- How to get the pixel height of a character in the specified font using the imagefontheight() function in PHP?
- How to get the value of a specific pixel in OpenCV using C++?
- How to set a single pixel using imagesetpixel() function in PHP?
- PHP – How to get the substitution character using mb_substitute_character()?
- How to get the width of a div element using jQuery?
- How to get the clipping rectangle using imagegetclip() function in PHP?
- How to get the width of the Tkinter widget?
- How to get the width of an element using jQuery?
- PHP – How to get the Unicode point value of a given character?
- How to get the height and width of the android.widget.ImageView?
- How to get the pixel depth and color depth of a screen in JavaScript?
- Set the width of a tab character with CSS
- How to get the Width and Height of the screen in JavaScript?
- How to get a part of string after a specified character in JavaScript?
- How to get or set the resolution of an image using imageresolution() function in PHP?
Advertisements