PHP Barcode Generator
Generate 1D barcodes as SVG, PNG, JPG, or HTML from PHP with no framework needed.
Repository Health
Technical Analysis
PHP Barcode Generator by Picqer is an easy-to-use, non-bloated, framework-independent library for creating 1D barcodes in PHP. It supports the most widely used standards — EAN-13, UPC, Code 128, Code 39, Code 93, MSI, Codabar, KIX, POSTNET, and more — and renders them as SVG, PNG, JPG, or HTML images.
Each output format has its own generator class, so you pick exactly the renderer you need and call a single generate method with the data, barcode type, and sizing. SVG and HTML output require no extensions, while PNG and JPG use GD or Imagick. The result is a dependency-light way to add scannable barcodes to invoices, labels, tickets, and warehouse workflows.
What You Get
- Generators for SVG, PNG, JPG, HTML, and dynamic HTML output
- Support for many 1D standards: EAN-13, UPC, Code 128, Code 39, Code 93, MSI, Codabar, KIX, and more
- A single generate() call per format with data, type, width, and height
- SVG and HTML rendering with no PHP extensions required
- PNG/JPG rendering via GD or Imagick
Common Use Cases
- Printing product barcodes (EAN/UPC) on labels and packaging
- Adding scannable codes to invoices, tickets, and shipping documents
- Generating warehouse and inventory labels for picking workflows
- Embedding barcodes as inline SVG or HTML in web pages
Under The Hood
Architecture - Barcode encoding is separated from rendering. A shared BarcodeGenerator base plus type classes under src/Types encode the input string for a given standard into a Barcode composed of BarcodeBar segments (widths and positions). Concrete generators — BarcodeGeneratorSVG, BarcodeGeneratorPNG, BarcodeGeneratorJPG, BarcodeGeneratorHTML, and BarcodeGeneratorDynamicHTML — plus a Renderers layer then draw those bars into the target format, so adding a new output format does not touch the encoding logic.
Tech Stack - PHP 8.2+ requiring ext-mbstring, with optional ext-gd or ext-imagick for PNG/JPG and ext-bcmath for Intelligent Mail Barcode. Development uses PHPUnit and PHPStan.
Code Quality - The library is deliberately non-bloated: small encoder classes per barcode type, dedicated renderer classes, and an Exceptions namespace for invalid input. A PHPUnit test suite and PHPStan analysis back the code, and the clean type/renderer split keeps each standard self-contained.
API Design - The public surface is a single generate() method per format generator, taking the data, a barcode-type constant, and sizing parameters, returning the image string. There is no configuration ceremony or global state, so producing a barcode is a one-line call and swapping output formats means swapping the generator class.