tc-lib-barcode

September 2, 2026 ยท View on GitHub

PHP library for generating linear, 2D and postal barcodes.

Latest Stable Version Build Coverage License Downloads

Sponsor on GitHub

๐Ÿ’– Part of the tc-lib-pdf / TCPDF ecosystem (100M+ installs). Sponsor its maintenance โ†’


Overview

tc-lib-barcode is a pure-PHP library that encodes data in 73 linear, 2D and postal barcode formats and outputs them as SVG, PNG, HTML, text grids, GD images or arrays of bar coordinates.

Namespace\Com\Tecnick\Barcode
AuthorNicola Asuni info@tecnick.com
LicenseGNU LGPL v3 - see LICENSE
API docshttps://tcpdf.org/docs/srcdoc/tc-lib-barcode
Packagisthttps://packagist.org/packages/tecnickcom/tc-lib-barcode

Why this library

  • One API for every format. getBarcodeObj() returns the same object for a UPC-A and a Han Xin Code; the same getInlineSvgCode(), getPngData(), getGrid() and getArray() methods work across all 73 types.
  • Pure PHP, one runtime dependency. Only tecnickcom/tc-lib-color, plus the gd, ctype and pcre extensions. bcmath and imagick are optional accelerators, never required.
  • Written to the published standards. Each symbology follows its own published specification, named alongside the format where one applies.
  • Covered by tests. Per-format encoding, ECC, size and input-validation suites, run under strict static analysis on every commit.
  • LGPL-3.0. Usable in closed-source applications.
  • Maintained. Part of the tc-lib-pdf / TCPDF ecosystem, in continuous development since 2015.

Supported Formats

Linear

FormatDescription
C39CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9
C39+CODE 39 + CHECKSUM
C39ECODE 39 EXTENDED
C39E+CODE 39 EXTENDED + CHECKSUM
C32CODE 32 (Italian Pharmacode - IMH - Radix 32)
C49CODE 49 (ANSI/AIM BC6)
PZNPZN (Pharmazentralnummer - IFA coding system)
LOGMARSLOGMARS (CODE 39 profile of MIL-STD-1189B)
C93CODE 93 - USS-93
S25Standard 2 of 5
S25+Standard 2 of 5 + CHECKSUM
S25IATA2 of 5 IATA (Computer Identics 2 of 5)
S25MATRIX2 of 5 Matrix
S25DATALOGIC2 of 5 Datalogic (China Post Code)
I25Interleaved 2 of 5
I25+Interleaved 2 of 5 + CHECKSUM
ITF14ITF-14 (GTIN-14 - GS1 General Specifications)
C128CODE 128
C128ACODE 128 A
C128BCODE 128 B
C128CCODE 128 C
C16KCODE 16K (stacked CODE 128)
GS1128GS1-128 (CODE 128 with GS1 Application Identifiers)
SSCC18SSCC-18 (GS1-128 with the Application Identifier 00)
GS114GS1-14 - EAN-14 - SCC-14 (GS1-128 with the Application Identifier 01)
DATABARGS1 DataBar Omnidirectional (ISO/IEC 24724)
DATABARTRUNCGS1 DataBar Truncated (ISO/IEC 24724)
DATABARSTACKGS1 DataBar Stacked (ISO/IEC 24724)
DATABARSTACKOMNIGS1 DataBar Stacked Omnidirectional (ISO/IEC 24724)
DATABARLIMITEDGS1 DataBar Limited (ISO/IEC 24724)
DATABAREXPGS1 DataBar Expanded (ISO/IEC 24724)
DATABAREXPSTACKGS1 DataBar Expanded Stacked (ISO/IEC 24724)
EAN2EAN 2-Digits UPC-Based Extension
EAN5EAN 5-Digits UPC-Based Extension
EAN8EAN 8
EAN13EAN 13
UPCAUPC-A
UPCEUPC-E
PLESSEYPlessey Code
MSIMSI (Variation of Plessey code)
MSI+MSI + CHECKSUM (modulo 11)
TELEPENTelepen (full ASCII)
CODABARCODABAR
CODE11CODE 11
PHARMAPHARMACODE
PHARMA2TPHARMACODE TWO-TRACKS
HIBC39HIBC in CODE 39 (ANSI/HIBC 2.6 and ANSI/HIBC 1.3)
HIBC128HIBC in CODE 128 (ANSI/HIBC 2.6 and ANSI/HIBC 1.3)
LRAW1D RAW MODE (comma-separated rows of 01 strings)

2D

FormatDescription
AZTECAZTEC Code (ISO/IEC 24778:2008)
AZTECRUNEAZTEC Rune (ISO/IEC 24778:2008 Annex A)
DATAMATRIXDATAMATRIX (ISO/IEC 16022)
DMREData Matrix Rectangular Extension (ISO/IEC 21471)
PDF417PDF417 (ISO/IEC 15438:2006)
PDF417CCompact PDF417 - truncated (ISO/IEC 15438:2006)
QRCODEQR-CODE
MICROQRMicro QR Code (ISO/IEC 18004)
HANXINHan Xin Code (GB/T 21049, ISO/IEC 20830)
HIBCDMHIBC in DATAMATRIX (ANSI/HIBC 2.6 and ANSI/HIBC 1.3)
HIBCQRHIBC in QR-CODE (ANSI/HIBC 2.6 and ANSI/HIBC 1.3)
HIBCAZHIBC in AZTEC Code (ANSI/HIBC 2.6 and ANSI/HIBC 1.3)
SRAW2D RAW MODE (comma-separated rows of 01 strings)

Postal

FormatDescription
POSTNETPOSTNET
PLANETPLANET
RMS4CCRMS4CC (Royal Mail 4-state Customer Bar Code)
KIXKIX (Klant index - Customer index)
JPPOSTJapan Post Customer Barcode
MAILMARKRoyal Mail Mailmark 4-state barcode (types C and L)
IDENTCODEDeutsche Post Identcode
LEITCODEDeutsche Post Leitcode
AUSPOSTAustralia Post 4-State Customer Barcode
IMBIMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
IMBPREIMB - Intelligent Mail Barcode pre-processed

Output Formats

  • SVG image (file, inline code, or standalone document)
  • PNG image (via GD or Imagick)
  • GD image object
  • HTML div elements
  • Character grid string
  • Array of bar coordinates

Width, height, padding, foreground and background color are set per barcode.


Requirements

  • PHP 8.2 or later
  • Extensions: gd
  • Optional extensions: bcmath (speeds up the arbitrary precision arithmetic used by the IMB and PDF417 types, a pure-PHP implementation is used when it is missing)
  • Composer

Installation

composer require tecnickcom/tc-lib-barcode

Quick Start

<?php

require_once __DIR__ . '/vendor/autoload.php';

$barcode = new \Com\Tecnick\Barcode\Barcode();
$bobj = $barcode->getBarcodeObj(
    type: 'QRCODE,H',
    code: 'https://tecnick.com',
    width: -4,
    height: -4,
    color: 'black',
    padding: [-2, -2, -2, -2],
)->setBackgroundColor('white');

echo $bobj->getInlineSvgCode();

For more formats and rendering options, see the example/ directory.


Development

make deps
make help
make qa

To preview the example app in a browser:

make server

Then open http://localhost:8000/ (served from the example/ directory).

To use a different port:

make server PORT=8080

Build artifacts and reports are generated in target/.


Packaging

make rpm
make deb

For system packages, bootstrap with:

require_once '/usr/share/php/Com/Tecnick/Barcode/autoload.php';

Identifiers issued by a registration body

The library encodes the data it is given. Several formats carry a number that only its registration body can issue, so a symbol is valid in its scheme only once that number has been obtained:

FormatIssued by
EAN, UPC, ITF-14, GS1-128, SSCC-18, GS1-14, GS1 DataBara GS1 member organisation, which issues the company prefix
HIBC39, HIBC128, HIBCDM, HIBCQR, HIBCAZHIBCC, which assigns the Labeler Identification Code
MAILMARKRoyal Mail, which issues the Supply Chain ID carried in the barcode
PZNIFA GmbH, which allocates the Pharmazentralnummer
IDENTCODE, LEITCODEDeutsche Post DHL, which assigns the customer number and the street codes
C32AIFA, which assigns the Italian AIC number

Trademarks

The names below identify the symbologies this library encodes and belong to their respective owners. They are used descriptively; no affiliation with or endorsement by their owners is claimed or implied.

NameOwner
QR CodeDENSO WAVE INCORPORATED
GS1, GS1-128, GS1 DataBarGS1 AISBL
MailmarkRoyal Mail Group Ltd
Intelligent MailUnited States Postal Service
PHARMA-CODELaetus GmbH
TelepenS.B. Electronic Systems Ltd
HIBC, HIBCCHealth Industry Business Communications Council
KIXPostNL
Identcode, LeitcodeDeutsche Post DHL

GS1 licenses the claims necessary to implement its standards under its IP Policy, to GS1 members and to the participants of the work group that developed the standard, rather than to the public at large.


Contributing

Contributions are welcome. Please read CONTRIBUTING.md, CODE_OF_CONDUCT.md, and SECURITY.md before submitting a pull request.