Manual - Label

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

  • __constructor__(string text, BCGFont font, int position, int 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(string 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(BCGFont 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(int position) — Sets the position associated with the label
    Description
    The 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 method SetRotationAngle().
    The default value is BCGLabel.Bottom.
  • GetAlignment() — Gets the alignment associated with the label
    Description
    See SetAlignment() for more details.
    Returns
    int
  • SetAlignment(int alignment) — Sets the alignment associated with the label
    Description
    The 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
    Use BCGLabel.Left and BCGLabel.Right for top and bottom positioned labels independent of the rotation angle. Therefore, use BCGLabel.Top and BCGLabel.Bottom for left and right positioned labels.
    The default value is BCGLabel.Center.
  • GetOffset() — Gets the offset associated with the label
    Description
    Gets the offset in pixels associated with the label.
    Returns
    int
  • SetOffset(int 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(int 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(float 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(BCGColor 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(Graphics im, int x1, int y1, int x2, int y2) — Draws the text on the image
    Description
    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.