Skip to content

Novis\Image\Barcode::Symbology

The barcode format that Barcode::render and Barcode::svg draw. A barcode format is also called a symbology.

Barcode::Symbology is declared in the class Novis\Image\Barcode.

Each format takes different data. The data must already contain its check digit.

  • Code128 takes any plain ASCII text, such as a tracking number.
  • Gs1128 takes GS1 element strings. Each one starts with its identifier in brackets, as in (01)09501101530003(10)ABC.
  • Ean13 takes the 13 digits printed on a product.
  • Ean8 takes 8 digits, for small products.
  • UpcA takes the 12 digits used on products in North America.
  • Code39 takes digits, capital letters, spaces and the characters - . $ / + %.
  • Itf14 takes the 14 digits printed on a shipping box.
  • DataMatrix takes any text and draws a square code.

The others draw lines of bars. Data that the format cannot contain throws a LogicError.

Examples

Every type and its data

<?nvs
// Shows the data each `Barcode::Symbology` takes, and the size of the image it draws.
use Novis\Image\Barcode;
use Novis\Image\Image;
// Each row is a type and data that the type can hold.
array<{ symbology: Barcode::Symbology, data: string }> $rows = [
{ symbology: Barcode::Symbology::Code128, data: 'Shop-42' },
{ symbology: Barcode::Symbology::Gs1128, data: '(01)09501101530003(10)ABC' },
{ symbology: Barcode::Symbology::Ean13, data: '4006381333931' },
{ symbology: Barcode::Symbology::Ean8, data: '96385074' },
{ symbology: Barcode::Symbology::UpcA, data: '036000291452' },
{ symbology: Barcode::Symbology::Code39, data: 'SHOP-42' },
{ symbology: Barcode::Symbology::Itf14, data: '15400141288763' },
{ symbology: Barcode::Symbology::DataMatrix, data: 'Shop order 1042' },
];
// This prints the width and height of each image in pixels.
// Only the `DataMatrix` image is square.
foreach ($rows as var $row) {
var $info = Image::info(Barcode::render($row->data, $row->symbology));
echo $row->data, ': ', $info->width, 'x', $info->height, "\n";
}
Output
Shop-42: 264x120
(01)09501101530003(10)ABC: 616x120
4006381333931: 230x120
96385074: 174x120
036000291452: 230x120
SHOP-42: 272x120
15400141288763: 308x120
Shop order 1042: 80x80