Manual - Label
Introduction
This class allows you to draw text with a desired TTF font on image resources.
Methods
BCGLabel's Methods
-
__constructor__(
$text ,$font ,$position ,$alignment ) — Creates the label with default or specific arguments - getText() — Gets the text associated with the label
-
setText(
$text ) — Sets the text associated with the label - getFont() — Gets the font associated with the label
-
setFont(
$font ) — Sets the font associated with the label - getPosition() — Gets the position associated with the label
-
setPosition(
$position ) — Sets the position associated with the label - getAlignment() — Gets the alignment associated with the label
-
setAlignment(
$alignment ) — Sets the alignment associated with the label - getOffset() — Gets the offset associated with the label
-
setOffset(
$offset ) — Sets the offset associated with the label - getSpacing() — Gets the spacing associated with the label
-
setSpacing(
$spacing ) — Sets the spacing associated with the label - getRotationAngle() — Gets the rotation angle associated with the label
-
setRotationAngle(
$rotationAngle ) — Sets the rotation angle associated with the label - getBackgroundColor() — Gets the background color associated with the label
-
setBackgroundColor(
$backgroundColor ) — Sets the background color associated with the label - getDimension() — Gets the dimension of the text
-
draw(
$im ,$x1 ,$y1 ,$x2 ,$y2 ) — Draws the text on the image
Code Example
// To get an example on how to use this class, check barcode classes.
Method explanations
-
__constructor__(
$text ,$font ,$position ,$alignment ) — Creates the label with default or specific argumentsDescriptionCreates the class. You can use no arguments to create the default, or specify the arguments in advance.
See the appropriate methods for more information. -
getText()
—
Gets the text associated with the label
DescriptionReturns the label.Returns
string -
setText(
$text ) — Sets the text associated with the labelDescriptionSets the text. -
getFont()
—
Gets the font associated with the label
DescriptionThe font implements the
BCGFont interface.ReturnsBCGFont -
setFont(
$font ) — Sets the font associated with the labelDescriptionSupports two different kind of fonts.
-BCGFontFile : User TTF font
-BCGFontPhp : Built-in PHP font
The default value is BCGFontPhp(5). -
getPosition()
—
Gets the position associated with the label
DescriptionSee setPosition() for more details.Returns
int -
setPosition(
$position ) — Sets the position associated with the labelDescriptionThe possible values for this argument are the following:
BCGLabel::POSITION_TOP : Writes the label at the top of the barcode
BCGLabel::POSITION_RIGHT : Writes the label at the right of the barcode
BCGLabel::POSITION_BOTTOM : Writes the label at the bottom of the barcode
BCGLabel::POSITION_LEFT : Writes the label at the left of the barcode
Note that the label will not be rotated by default if it's placed to the left or right. In order to rotate the barcode, you must use the methodsetRotationAngle() .
The default value isBCGLabel::POSITION_BOTTOM . -
getAlignment()
—
Gets the alignment associated with the label
DescriptionSee setAlignment() for more details.Returns
int -
setAlignment(
$alignment ) — Sets the alignment associated with the labelDescriptionThe possible values for this argument are as follows:
BCGLabel::ALIGN_LEFT : Aligns the label to the left of the barcode
BCGLabel::ALIGN_RIGHT : Aligns the label to the right of the barcode
BCGLabel::ALIGN_CENTER : Aligns the label to the center of the barcode
BCGLabel::ALIGN_TOP : Aligns the label to the top of the barcode
BCGLabel::ALIGN_BOTTOM : Aligns the label to the bottom of the barcode
UseBCGLabel::ALIGN_LEFT andBCGLabel::ALIGN_RIGHT for top and bottom positioned labels independent of the rotation angle. Therefore, useBCGLabel::ALIGN_TOP andBCGLabel::ALIGN_BOTTOM for left and right positioned labels.
The default value isBCGLabel::ALIGN_CENTER . -
getOffset()
—
Gets the offset associated with the label
DescriptionGets the offset in pixels associated with the label.Returns
int -
setOffset(
$offset ) — Sets the offset associated with the labelDescriptionSets the offset in pixels associated with the label.
Positive offset is pushing the label to the right for top and bottom positioned labels, and is pushing the labels to the bottom for left and right positioned label.
You can use negative numbers to do the opposite.
The default value is 0. -
getSpacing()
—
Gets the spacing associated with the label
DescriptionGets the spacing between the label and the barcode in pixels.Returns
int -
setSpacing(
$spacing ) — Sets the spacing associated with the labelDescriptionSets the spacing between the label and the barcode in pixels.
For top and bottom positioned label, this corresponds to the distance between the bottom or top part of the label.
For left and right positioned label, this is accordingly the distance between the right or left part of the label.
The default value is 4. -
getRotationAngle()
—
Gets the rotation angle associated with the label
DescriptionGets the rotation angle in degrees clockwise.Returns
int -
setRotationAngle(
$rotationAngle ) — Sets the rotation angle associated with the labelDescriptionSets the rotation angle in degrees clockwise. This argument accepts only the following:
-0 : By default, no rotation is applied
-90 : Rotates 90° clockwise the label
-180 : Rotates 180° clockwise the label
-270 : Rotates 270° clockwise the label
The default value is 0.
Note that your server may not support the imagerotate() function. -
getBackgroundColor()
—
Gets the background color associated with the label
DescriptionGets the background color.Returns
-
setBackgroundColor(
$backgroundColor ) — Sets the background color associated with the labelDescriptionSets the background color, used for rotation purposes.
This method is internal; do not use this function directly. -
getDimension()
—
Gets the dimension of the text
DescriptionGets the width and height in pixels depending on the font and the entered text.Returnsarray(int, int) - [0] is the width, [1] is the height
-
draw(
$im ,$x1 ,$y1 ,$x2 ,$y2 ) — Draws the text on the imageDescription$image is an image resource.
The arguments$x1 and$y1 correspond to the top left corner position of the barcode.
The arguments$x2 and$y2 correspond to the bottom right corner position of the barcode.