PHPackages                             isahaq/barcode - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. isahaq/barcode

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

isahaq/barcode
==============

A universal barcode generator package supporting 32+ barcode types and multiple output formats (PNG, SVG, HTML, JPG, PDF), with batch generation, validation, CLI, and full Laravel integration.

v1.4.0(3mo ago)22102MITPHPPHP ^8.0CI passing

Since Jul 13Pushed 3w agoCompare

[ Source](https://github.com/isahaq1/barcodeGeneratorPkg)[ Packagist](https://packagist.org/packages/isahaq/barcode)[ Docs](https://github.com/isahaq1/barcodeGeneratorPkg)[ RSS](/packages/isahaq-barcode/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (5)Versions (5)Used By (0)

 [![isahaq/barcode — Generate 44 barcode types and modern QR codes in PHP](https://raw.githubusercontent.com/isahaq1/barcodeGeneratorPkg/main/banner.png)](https://raw.githubusercontent.com/isahaq1/barcodeGeneratorPkg/main/banner.png)

isahaq/barcode
==============

[](#isahaqbarcode)

 A dependency-free PHP barcode generator: **44 barcode types**, multiple output formats, a CLI, and first-class Laravel integration.

 [![Latest Version on Packagist](https://camo.githubusercontent.com/776a3f98c2157dea4fa168e929669f90588d8a1b9e7cae04a8ca1216e0b526d0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6973616861712f626172636f64652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/isahaq/barcode) [![Total Downloads](https://camo.githubusercontent.com/1a2ad692195f9710893f75835aa6611aea23e5c3ada974214b5c62d58d475aff/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6973616861712f626172636f64652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/isahaq/barcode) [![Tests](https://camo.githubusercontent.com/8b55818f39d4d8fe3b01f1dd8ae45eb35c5c21c5e2db531b1262faeb4dfc47b4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f697361686171312f626172636f646547656e657261746f72506b672f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/isahaq1/barcodeGeneratorPkg/actions/workflows/tests.yml) [![PHP Version](https://camo.githubusercontent.com/32ace01dccdff98d4a754854575fa8679682a6559145c8d920ce8c288a4539e6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6973616861712f626172636f64652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/isahaq/barcode) [![License](https://camo.githubusercontent.com/0ae942885040798b03d074bf43df9064ce2872ee454a207ffb241ae449047629/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6973616861712f626172636f64652e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Usage](#usage)
    - [Plain PHP](#plain-php)
    - [The service class](#the-service-class)
    - [QR codes](#qr-codes)
    - [Batch generation](#batch-generation)
    - [Validation](#validation)
- [Laravel](#laravel)
- [Command Line](#command-line)
- [Supported Barcode Types](#supported-barcode-types)
- [Output Formats](#output-formats)
- [Rendering Options](#rendering-options)
- [Known Limitations](#known-limitations)
- [Testing](#testing)
- [Contributing](#contributing)
- [Security](#security)
- [Changelog](#changelog)
- [License](#license)

Features
--------

[](#features)

- **44 barcode types** — linear, EAN/UPC, postal, 2D matrix, and stacked symbologies
- **Multiple output formats** — PNG, SVG, and HTML built in; JPG and PDF via dedicated renderers
- **QR codes** — including centered logos, labels, and selectable error-correction levels
- **Laravel integration** — auto-discovered service provider and `Barcode` facade
- **Batch generation** — encode many payloads through one type/renderer pair
- **Validation** — check a payload against a symbology before you render it
- **No runtime Composer dependencies** — pure PHP plus standard extensions

Requirements
------------

[](#requirements)

RequirementNotesPHP &gt;= 8.0`ext-mbstring`Required.`ext-gd`Required for PNG and JPG output. SVG and HTML work without it.`illuminate/support` 8–12Only needed for the Laravel facade and service provider.`setasign/fpdf` (or any `FPDF` class)Optional, only for PDF output.Installation
------------

[](#installation)

```
composer require isahaq/barcode
```

On Laravel 5.5+ the service provider and facade are registered automatically via package discovery. For older versions, register them by hand in `config/app.php`:

```
'providers' => [
    Isahaq\Barcode\Providers\BarcodeServiceProvider::class,
],

'aliases' => [
    'Barcode' => Isahaq\Barcode\Facades\Barcode::class,
],
```

Quick Start
-----------

[](#quick-start)

```
use Isahaq\Barcode\Services\BarcodeService;

$barcode = new BarcodeService();

// PNG bytes for a Code 128 barcode
file_put_contents('barcode.png', $barcode->png('1234567890'));

// An SVG EAN-13
file_put_contents('barcode.svg', $barcode->svg('590123412345', 'ean13'));

// Inline in a web page
$png = $barcode->png('ABC123', 'code39');
echo '';
```

Every method returns the encoded image as a **string of bytes** — write it to disk, stream it in a response, or base64-encode it into an `` tag.

Usage
-----

[](#usage)

### Plain PHP

[](#plain-php)

Compose a type and a renderer directly when you want full control:

```
use Isahaq\Barcode\Types\Code128;
use Isahaq\Barcode\Renderers\PNGRenderer;

$type     = new Code128();
$renderer = new PNGRenderer();

$barcode = $type->encode('1234567890');
$png     = $renderer->render($barcode, ['height' => 80, 'width' => 3]);

file_put_contents('barcode.png', $png);
```

Colours are set on the renderer, not through the options array:

```
$renderer = new PNGRenderer();
$renderer->setForegroundColor([220, 38, 38]);   // RGB
$renderer->setBackgroundColor([255, 255, 255]);

$png = $renderer->render($barcode);
```

### The service class

[](#the-service-class)

`BarcodeService` resolves types and renderers from strings, which is usually more convenient:

```
use Isahaq\Barcode\Services\BarcodeService;

$service = new BarcodeService();

$service->png('1234567890', 'code128');
$service->svg('590123412345', 'ean13');
$service->html('ABC-123', 'code39');

// The general form: make(type, format, data, options)
$service->make('code128', 'png', '1234567890', [
    'height' => 60,
    'width'  => 2,
    'margin' => 10,
]);
```

Unknown type names fall back to Code 128, and unknown formats fall back to PNG — validate input yourself if that matters to you.

### QR codes

[](#qr-codes)

QR codes are generated through `ModernQRCode`, which supports logos, labels, and error correction:

```
use Isahaq\Barcode\Utils\ModernQRCode;

$qr = new ModernQRCode();
$qr->setData('https://example.com')
   ->setSize(300)
   ->setMargin(10)
   ->setErrorCorrection('H')          // L, M, Q, or H
   ->setForegroundColor([0, 0, 0])
   ->setBackgroundColor([255, 255, 255])
   ->setLabel('Scan me')
   ->setLogo('path/to/logo.png', 60); // 60 = logo size in pixels

file_put_contents('qr.png', $qr->writeString());
// or write straight to disk
$qr->writeFile('qr.png');
```

Use error-correction level `H` whenever you overlay a logo, so the code stays scannable.

### Batch generation

[](#batch-generation)

`BatchGenerator::generate()` is static and takes an instantiated type and renderer. It returns an array of encoded images keyed in the same order as the input:

```
use Isahaq\Barcode\Utils\BatchGenerator;
use Isahaq\Barcode\Types\Code128;
use Isahaq\Barcode\Renderers\PNGRenderer;

$images = BatchGenerator::generate(
    new Code128(),
    new PNGRenderer(),
    ['ABC123', 'DEF456', 'GHI789'],
    ['height' => 60]
);

foreach ($images as $i => $png) {
    file_put_contents("barcode-{$i}.png", $png);
}
```

### Validation

[](#validation)

`Validator::validate()` is static and accepts an optional by-reference error message:

```
use Isahaq\Barcode\Utils\Validator;
use Isahaq\Barcode\Types\EAN13;

$error = null;

if (Validator::validate(new EAN13(), '5901234123457', $error)) {
    // safe to render
} else {
    echo $error; // "Invalid data for barcode type."
}
```

Laravel
-------

[](#laravel)

The facade proxies to `BarcodeService`, so every service method is available statically:

```
use Isahaq\Barcode\Facades\Barcode;

Barcode::png('1234567890', 'code128');
Barcode::svg('590123412345', 'ean13');
Barcode::make('code39', 'png', 'ABC-123', ['height' => 60]);
```

Return a barcode straight from a controller or route:

```
Route::get('/barcode/{data}', function (string $data) {
    return response(Barcode::png($data, 'code128'))
        ->header('Content-Type', 'image/png');
});
```

The facade also exposes a `modernQr()` helper that takes a single options array:

```
$qr = Barcode::modernQr([
    'data'              => 'https://example.com',
    'size'              => 300,
    'margin'            => 10,
    'error_correction'  => 'H',
    'foreground_color'  => [0, 0, 0],
    'background_color'  => [255, 255, 255],
    'label'             => 'Scan me',
    'logoPath'          => public_path('images/logo.png'),
    'logoSize'          => 60,
]);

return response($qr)->header('Content-Type', 'image/png');
```

In Blade templates:

```

```

Resolve the service from the container if you prefer injection over the facade:

```
public function show(Request $request, \Isahaq\Barcode\Services\BarcodeService $barcode)
{
    return response($barcode->png($request->input('data'), 'code128'))
        ->header('Content-Type', 'image/png');
}
```

Command Line
------------

[](#command-line)

The package ships a small generator script:

```
php vendor/isahaq/barcode/src/CLI/generate.php --data="1234567890" --output=barcode.png
```

Omit `--output` to write the raw image to STDOUT. Note that this script currently always emits a Code 128 PNG — see [Known Limitations](#known-limitations).

Supported Barcode Types
-----------------------

[](#supported-barcode-types)

Pass any of these names as the `$type` argument. Names are case-insensitive.

### Code 128 family

[](#code-128-family)

`code128` · `code128a` · `code128b` · `code128c` · `code128auto`

### Code 39 family

[](#code-39-family)

`code39` · `code39checksum` · `code39e` · `code39echecksum` · `code39auto`

### Other linear

[](#other-linear)

`code93` · `code25` · `code25auto` · `code32` (Italian Pharmacode) · `standard25` · `standard25checksum` · `interleaved25` · `interleaved25checksum` · `interleaved25auto` · `msi` · `msichecksum` · `msiauto`

### EAN / UPC

[](#ean--upc)

`ean2` · `ean5` · `ean8` · `ean13` · `itf14` · `upca` · `upce`

### Postal

[](#postal)

`postnet` · `planet` · `rms4cc` · `kix` · `imb`

### Specialized

[](#specialized)

`codabar` · `code11` · `pharmacode` · `pharmacodetwotracks`

### 2D matrix

[](#2d-matrix)

`datamatrix` · `aztec` · `pdf417` · `maxicode`

### Stacked linear

[](#stacked-linear)

`code16k` · `code49`

### Choosing a type

[](#choosing-a-type)

TypeExample payloadBest for`code128``ABC123`General purpose, high density`code39``ABC-123`Alphanumeric, inventory, legacy scanners`ean13``5901234123457`Retail products (13 digits)`ean8``96385074`Small retail products (8 digits)`upca``036000291452`North American retail`itf14``12345678901231`Shipping cartons`codabar``A12345A`Libraries, blood banks (needs A–D start/stop)`datamatrix`Any dataTiny marking areas, pharmaceutical`pdf417`Large dataID cards, documents, boarding passesModern QRAny dataURLs, contact details, paymentsOutput Formats
--------------

[](#output-formats)

FormatHow to get itNotesPNG`png()` / `make(..., 'png', ...)`Requires `ext-gd`.SVG`svg()` / `make(..., 'svg', ...)`Scalable, no extensions needed.HTML`html()` / `make(..., 'html', ...)``` markup, no extensions needed.JPG`new JPGRenderer()` directlyRequires `ext-gd`. Not resolvable by format string.PDF`new PDFRenderer()` directlyRequires an `FPDF` class to be installed.JPG and PDF are not wired into the service's format resolver, so request them through their renderers:

```
use Isahaq\Barcode\Types\Code128;
use Isahaq\Barcode\Renderers\JPGRenderer;

$jpg = (new JPGRenderer())->render((new Code128())->encode('1234567890'));
file_put_contents('barcode.jpg', $jpg);
```

Rendering Options
-----------------

[](#rendering-options)

Options are passed as the last argument to `render()`, `make()`, `png()`, `svg()`, and `html()`.

### PNG renderer

[](#png-renderer)

OptionDefaultDescription`width``3`Width **multiplier** per module, not the total pixel width.`height``50`Barcode height in pixels.`margin``20`Space around the symbol.`text`the encoded dataHuman-readable line; pass `' '` to hide it.`font_size``5`Built-in GD font size, 1–5.`narrow` / `wide``2` / `5`Narrow and wide bar widths for two-width symbologies.`quiet_zone``10`Quiet zone width for symbologies that require one.`module_size``8`Module size for 2D matrix types.### SVG renderer

[](#svg-renderer)

OptionDefaultDescription`widthFactor``2`Width multiplier per module.`height``50`Barcode height.Foreground and background colours are set with `setForegroundColor()` and `setBackgroundColor()`on the renderer instance, and are ignored if passed in the options array.

Known Limitations
-----------------

[](#known-limitations)

Being upfront about the rough edges in the current release:

- **`qrcode` and `microqr` are not usable as type names.** `BarcodeService::make('qrcode', ...)`and `QrCodeBuilder` both reference classes that are not shipped and will throw `Error: Class not found`. Use [`ModernQRCode`](#qr-codes) or `Barcode::modernQr()` instead.
- **The CLI ignores `--type` and `--format`.** It always produces a Code 128 PNG. It also resolves the autoloader relative to the package directory, so it is most reliable when run from a clone.
- **`jpg` and `pdf` are not valid format strings.** Requesting them from `make()` silently returns PNG. Instantiate `JPGRenderer` or `PDFRenderer` directly.
- **`ext-gd` is not declared in `composer.json`** even though PNG and JPG output need it.

Contributions that close any of these gaps are very welcome.

Testing
-------

[](#testing)

```
composer test
```

Or run PHPUnit directly:

```
vendor/bin/phpunit
```

Other useful scripts:

```
composer format   # apply PHP-CS-Fixer
composer lint     # syntax-check src/ and tests/
```

Contributing
------------

[](#contributing)

Pull requests are welcome. Please read [CONTRIBUTING.md](CONTRIBUTING.md) first; in short:

1. Fork the repository and create a branch off `main`.
2. Follow PSR-12 and keep the existing code style.
3. Add tests for anything you change.
4. Make sure `composer test` passes, then open a pull request.

By participating you agree to the [Code of Conduct](CODE_OF_CONDUCT.md).

Security
--------

[](#security)

If you discover a security issue, please review [SECURITY.md](SECURITY.md) and report it privately to **** rather than opening a public issue.

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for release history.

License
-------

[](#license)

Released under the [MIT License](LICENSE).

Credits
-------

[](#credits)

Built and maintained by [Isahaq](https://github.com/isahaq1). Thanks to everyone who has reported issues and contributed improvements.

 Found this useful? Consider starring the repository.

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance89

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~98 days

Total

4

Last Release

106d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/11f213329a74dc5367c135ed69a8595ed2fc0709ca0617a99c4e39d342784a54?d=identicon)[isahaq](/maintainers/isahaq)

---

Top Contributors

[![isahaq1](https://avatars.githubusercontent.com/u/28819010?v=4)](https://github.com/isahaq1 "isahaq1 (73 commits)")[![bdisahaq](https://avatars.githubusercontent.com/u/276251349?v=4)](https://github.com/bdisahaq "bdisahaq (3 commits)")

---

Tags

phpqrcodelaravelgeneratorpdf417barcodeEAN13code128batch generationData Matrix

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/isahaq-barcode/health.svg)

```
[![Health](https://phpackages.com/badges/isahaq-barcode/health.svg)](https://phpackages.com/packages/isahaq-barcode)
```

###  Alternatives

[akira/laravel-qrcode

A clean, modern, and easy-to-use QR code generator for Laravel

497.2k](/packages/akira-laravel-qrcode)[forjedio/inertia-table

Backend-driven dynamic tables for Laravel + Inertia.js

272.0k](/packages/forjedio-inertia-table)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
