Introduction
This class allows you to draw text with a desired TTF font on GD2 images.
Depending on the font and size you choose, PHP may clip the right side of the label if it's aligned on the right. This is due to a PHP bug not returning the correct bounding box for the label. To counteract this problem, you can change the PHP_BOX_FIX value in the file in order to make the bounding box larger on the right by an amount of X pixels.
The default value is 0.
BCGFontFile's Methods
- __construct($fontPath, $size) — Creates the font with the size
- getDimension() — Gets the dimension of the text
- draw($im, $color, $x, $y) — Draws the text on the image
Code Example
// To get an example on how to use this class, check barcode classes. Methods Explanation
-
__construct($fontPath, $size)
— Creates the font with the size DescriptionCreates the class. The first argument is the path of the .ttf file you want to use. The second argument is the size in point (pt) of the font you want to use.
-
getDimension()
— Gets the dimension of the text DescriptionGets the width and height in pixel depending on the font and the entered text.Returnsarray(int, int) - [0] is the width, [1] is the height
-
draw($im, $color, $x, $y)
— Draws the text on the image Description$im is a GD2 image resource.
Draws the text with the color $color at the position $x, $y. $color must be a color already associated with the GD2 image. If you used a BCGColor color, you will have to use the allocate() method first.
