Manual - BCGLabel

Introduction

This class allows you to draw text with a desired TTF font on image resources.

Methods

BCGLabel's Methods

Code Example


// To get an example on how to use this class, check barcode classes.

Method explanations

  • __construct($text, $font, $position, $alignment) — Creates the label with default or specific arguments
    Description
    Creates 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
    Description
    Returns the label.
    Returns
    string
  • setText($text) — Sets the text associated with the label
    Description
    Sets the text.
  • getFont() — Gets the font associated with the label
    Description
    The font implements the BCGFont interface.
    Returns
    BCGFont
  • setFont($font) — Sets the font associated with the label
    Description
    Supports 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
    Description
    See setPosition() for more details.
    Returns
    int
  • setPosition($position) — Sets the position associated with the label
    Description
    The 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 method setRotationAngle().
    The default value is BCGLabel::POSITION_BOTTOM.
  • getAlignment() — Gets the alignment associated with the label
    Description
    See setAlignment() for more details.
    Returns
    int
  • setAlignment($alignment) — Sets the alignment associated with the label
    Description
    The 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
    Use BCGLabel::ALIGN_LEFT and BCGLabel::ALIGN_RIGHT for top and bottom positioned labels independent of the rotation angle. Therefore, use BCGLabel::ALIGN_TOP and BCGLabel::ALIGN_BOTTOM for left and right positioned labels.
    The default value is BCGLabel::ALIGN_CENTER.
  • getOffset() — Gets the offset associated with the label
    Description
    Gets the offset in pixels associated with the label.
    Returns
    int
  • setOffset($offset) — Sets the offset associated with the label
    Description
    Sets 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
    Description
    Gets the spacing between the label and the barcode in pixels.
    Returns
    int
  • setSpacing($spacing) — Sets the spacing associated with the label
    Description
    Sets 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
    Description
    Gets the rotation angle in degrees clockwise.
    Returns
    int
  • setRotationAngle($rotationAngle) — Sets the rotation angle associated with the label
    Description
    Sets 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
    Description
    Gets the background color.
    Returns
  • setBackgroundColor($backgroundColor) — Sets the background color associated with the label
    Description
    Sets the background color, used for rotation purposes.
    This method is internal; do not use this function directly.
  • getDimension() — Gets the dimension of the text
    Description
    Gets the width and height in pixels depending on the font and the entered text.
    Returns
    array(int, int) - [0] is the width, [1] is the height
  • draw($im, $x1, $y1, $x2, $y2) — Draws the text on the image
    Description
    $im 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.