Table of contents
Namespace: Com\Tecnick\Barcode
abstract class Type extends Convert implements Model
Extends: Convert
Implements: Model
Source: src/Type.php:42
Barcode Type class
Methods
__construct()
Initialize a new barcode object
public __construct(
string $code,
int $width = -1,
int $height = -1,
string $color = 'black',
(int|float|string)[] $params = [],
array{int, int, int, int} $padding = [0, 0, 0, 0]
)
Parameters:
$code(string): Barcode content$width(int): Barcode width in user units (excluding padding). A negative value indicates the multiplication factor for each column.$height(int): Barcode height in user units (excluding padding). A negative value indicates the multiplication factor for each row.$color(string): Foreground color in Web notation (color name, or hexadecimal code, or CSS syntax) or PDF spot color name$params((int|float|string)[]): Array containing extra parameters for the specified barcode type$padding(array{int, int, int, int}): Additional padding to add around the barcode (top, right, bottom, left) in user units. A negative value indicates the number of rows or columns.
Throws:
Source: src/Type.php:66
getArray()
Get the barcode raw array
public getArray(): array{'type': string, 'format': string, 'params': (int|float|string)[], 'code': string, 'extcode': string, 'ncols': int, 'nrows': int, 'width': int, 'height': int, 'width_ratio': float, 'height_ratio': float, 'padding': array{'T': int, 'R': int, 'B': int, 'L': int}, 'full_width': int, 'full_height': int, 'color_obj': Rgb, 'bg_color_obj': ?Rgb, 'bars': array{int, int, int, int}[]}
Returns: array{’type’: string, ‘format’: string, ‘params’: (int|float|string)[], ‘code’: string, ’extcode’: string, ’ncols’: int, ’nrows’: int, ‘width’: int, ‘height’: int, ‘width_ratio’: float, ‘height_ratio’: float, ‘padding’: array{‘T’: int, ‘R’: int, ‘B’: int, ‘L’: int}, ‘full_width’: int, ‘full_height’: int, ‘color_obj’: Rgb, ‘bg_color_obj’: ?Rgb, ‘bars’: array{int, int, int, int}[]}
Source: src/Type.php:258
getBarsArrayXYWH()
Get the array containing all the formatted bars coordinates (x, y, width, height)
public getBarsArrayXYWH(): array<int,array{float, float, float, float}>
Returns: array<int,array{float, float, float, float}>
Source: src/Type.php:723
getBarsArrayXYXY()
Get the array containing all the formatted bars coordinates (x1, y1, x2, y2)
public getBarsArrayXYXY(): array<int,array{float, float, float, float}>
Returns: array<int,array{float, float, float, float}>
Source: src/Type.php:684
getExtendedCode()
Get the extended code (code + checksum)
public getExtendedCode(): string
Returns: string
Source: src/Type.php:284
getGd()
Get the barcode as GD image object (requires GD library)
public getGd(): GdImage
Returns: GdImage
Throws:
- Exception: if the GD library is not installed or the image is too large
Source: src/Type.php:635
getGrid()
Get a raw barcode string representation using characters
public getGrid(string $space_char = '0', string $bar_char = '1'): string
Parameters:
$space_char(string): Character or string to use for filling empty spaces$bar_char(string): Character or string to use for filling bars
Returns: string
Source: src/Type.php:668
getHtmlDiv()
Get an HTML representation of the barcode.
public getHtmlDiv(): string
Returns: string: HTML code (DIV block)
Source: src/Type.php:428
getInlineSvgCode()
Get the barcode as inline SVG code.
public getInlineSvgCode(): string
Returns: string: Inline SVG code.
Source: src/Type.php:339
getPng()
Get Barcode as PNG Image (requires GD or Imagick library)
public getPng(string|null $filename = null): void
Parameters:
$filename(string|null): The file name without extension (optional). Only allows alphanumeric characters, underscores and hyphens. Defaults to a md5 hash of the data. The file extension is always ‘.png’.
Throws:
- Exception: in case image generation fails
Source: src/Type.php:466
getPngData()
Get the barcode as PNG image (requires GD or Imagick library)
public getPngData(bool $imagick = true): string
Parameters:
$imagick(bool): If true try to use the Imagick extension
Returns: string: PNG image data
Throws:
- Exception: in case image generation fails or neither extension is loaded
Source: src/Type.php:480
getPngDataImagick()
Get the barcode as PNG image (requires Imagick library)
public getPngDataImagick(): string
Returns: string
Throws:
- Exception: if the Imagick library is not installed or the image is too large
Source: src/Type.php:563
getSvg()
Get the barcode as SVG image object.
public getSvg(string|null $filename = null): void
Parameters:
$filename(string|null): The file name without extension (optional). Only allows alphanumeric characters, underscores and hyphens. Defaults to a md5 hash of the data. The file extension is always ‘.svg’.
Source: src/Type.php:329
getSvgCode()
Get the barcode as SVG code, including the XML declaration.
public getSvgCode(): string
Returns: string: SVG code
Source: src/Type.php:418
setBackgroundColor()
Set the background color
public setBackgroundColor(string $color): static
Parameters:
$color(string): Background color in Web notation (color name, or hexadecimal code, or CSS syntax) or PDF spot color name
Returns: static
Throws:
- Exception: in case of color error
Source: src/Type.php:198
setColor()
Set the color of the bars.
An empty or transparent foreground color is rejected with a BarcodeException.
public setColor(string $color): static
Parameters:
$color(string): Foreground color in Web notation (color name, or hexadecimal code, or CSS syntax) or PDF spot color name
Returns: static
Throws:
Source: src/Type.php:179
setSize()
Set the size of the barcode to be exported
public setSize(int $width, int $height, array{int, int, int, int} $padding = [0, 0, 0, 0]): static
Parameters:
$width(int): Barcode width in user units (excluding padding). A negative value indicates the multiplication factor for each column.$height(int): Barcode height in user units (excluding padding). A negative value indicates the multiplication factor for each row.$padding(array{int, int, int, int}): Additional padding to add around the barcode (top, right, bottom, left) in user units. A negative value indicates the number of rows or columns.
Returns: static
Throws:
- Exception: in case of an empty barcode or invalid padding
Source: src/Type.php:109
Inherited members
From Convert
- getGridArray(): Get a raw barcode grid array