Manual - Label
Introduction
This class allows you to draw text with a desired TTF font on image resources.
Methods
BCGLabel's Methods
-
__constructor__(string
text , BCGFontfont , intposition , intalignment ) — Creates the label with default or specific arguments - GetText() — Gets the text associated with the label
-
SetText(string
text ) — Sets the text associated with the label - GetFont() — Gets the font associated with the label
-
SetFont(BCGFont
font ) — Sets the font associated with the label - GetPosition() — Gets the position associated with the label
-
SetPosition(int
position ) — Sets the position associated with the label - GetAlignment() — Gets the alignment associated with the label
-
SetAlignment(int
alignment ) — Sets the alignment associated with the label - GetOffset() — Gets the offset associated with the label
-
SetOffset(int
offset ) — Sets the offset associated with the label - GetSpacing() — Gets the spacing associated with the label
-
SetSpacing(int
spacing ) — Sets the spacing associated with the label - GetRotationAngle() — Gets the rotation angle associated with the label
-
SetRotationAngle(float
rotationAngle ) — Sets the rotation angle associated with the label - GetBackgroundColor() — Gets the background color associated with the label
-
SetBackgroundColor(BCGColor
backgroundColor ) — Sets the background color associated with the label - GetDimension() — Gets the dimension of the text
-
Draw(Graphics
im , intx1 , inty1 , intx2 , inty2 ) — Draws the text on the image
Code Example
// To get an example on how to use this class, check barcode classes.
Method explanations
-
__constructor__(string
text , BCGFontfont , intposition , intalignment ) — 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(string
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(BCGFont
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(int
position ) — Sets the position associated with the labelDescriptionThe possible values for this argument are the following:
BCGLabel.Top : Writes the label at the top of the barcode
BCGLabel.Right : Writes the label at the right of the barcode
BCGLabel.Bottom : Writes the label at the bottom of the barcode
BCGLabel.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.Bottom . -
GetAlignment()
—
Gets the alignment associated with the label
DescriptionSee SetAlignment() for more details.Returns
int -
SetAlignment(int
alignment ) — Sets the alignment associated with the labelDescriptionThe possible values for this argument are as follows:
BCGLabel.Left : Aligns the label to the left of the barcode
BCGLabel.Right : Aligns the label to the right of the barcode
BCGLabel.Center : Aligns the label to the center of the barcode
BCGLabel.Top : Aligns the label to the top of the barcode
BCGLabel.Bottom : Aligns the label to the bottom of the barcode
UseBCGLabel.Left andBCGLabel.Right for top and bottom positioned labels independent of the rotation angle. Therefore, useBCGLabel.Top andBCGLabel.Bottom for left and right positioned labels.
The default value isBCGLabel.Center . -
GetOffset()
—
Gets the offset associated with the label
DescriptionGets the offset in pixels associated with the label.Returns
int -
SetOffset(int
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(int
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(float
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(BCGColor
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(Graphics
im , intx1 , inty1 , intx2 , inty2 ) — Draws the text on the imageDescriptionimage is an image resource.
The argumentsx1 andy1 correspond to the top left corner position of the barcode.
The argumentsx2 andy2 correspond to the bottom right corner position of the barcode.