PHPackages                             laikait/barcode-generator - 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. laikait/barcode-generator

ActiveLibrary

laikait/barcode-generator
=========================

A lightweight PHP barcode generator library supporting multiple formats with SVG and PNG output.

v1.0.0(2mo ago)00MITPHPPHP &gt;=8.1

Since Mar 9Pushed 2mo agoCompare

[ Source](https://github.com/laikait/barcode-generator)[ Packagist](https://packagist.org/packages/laikait/barcode-generator)[ RSS](/packages/laikait-barcode-generator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

Laika Barcode Generator
=======================

[](#laika-barcode-generator)

A lightweight PHP 8.1+ barcode generator library supporting 1D and 2D barcode formats with **SVG and PNG** output, watermarks, and file saving — zero runtime dependencies.

---

Supported Formats
-----------------

[](#supported-formats)

### 1D Barcodes — `Laika\Barcode\Barcode`

[](#1d-barcodes--laikabarcodebarcode)

KeyFormatInput`code128`Code 128Any printable ASCII`code39`Code 39A–Z, 0–9, `-` `.` ` ` `$ / + %``ean13`EAN-1312 or 13 digits`ean8`EAN-87 or 8 digits`upca`UPC-A11 or 12 digits### 2D Barcodes — `Laika\Barcode\QrCode`

[](#2d-barcodes--laikabarcodeqrcode)

FormatVersionsEC LevelsInputQR Code1–10L, M, Q, HAny bytes/UTF-8---

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

[](#requirements)

- PHP **8.1+**
- GD extension *(only for PNG output)*

---

Installation
------------

[](#installation)

```
composer require laika/barcode
```

---

1D Barcodes
-----------

[](#1d-barcodes)

### SVG

[](#svg)

```
use Laika\Barcode\Barcode;

$svg = Barcode::type('code128')->data('Hello, World!')->svg();

header('Content-Type: image/svg+xml');
echo $svg;
```

### PNG *(requires GD)*

[](#png-requires-gd)

```
$png = Barcode::type('ean13')->data('590123412345')->png();

header('Content-Type: image/png');
echo $png;
```

### Save to File

[](#save-to-file)

Format is inferred from the file extension (`.svg` or `.png`). Directories are created automatically.

```
// Returns the resolved absolute path
$path = Barcode::type('code128')->data('ABC-123')->save('/var/www/barcodes/label.svg');
$path = Barcode::type('ean13')->data('590123412345')->save('/var/www/barcodes/product.png');
```

### Inline in HTML

[](#inline-in-html)

```
$svg = Barcode::type('ean8')->data('9638507')->svg();
echo '' . $svg . '';
```

### Options

[](#options)

All options can be passed to `->options([...])` (builder-level) or directly to `->svg([...])` / `->png([...])` / `->save($path, [...])`.

**SVG options:**

OptionTypeDefaultDescription`height``int``80`Bar height in pixels`module_width``int``2`Width of one narrow module (px)`margin``int``10`Side/top/bottom margin (px)`color``string``#000000`Bar and label colour (hex)`bg``string``#ffffff`Background colour, `''` = transparent`show_label``bool``true`Print data label below bars`font_size``int``12`Label font size in px`watermark_text``string``''`Diagonal overlay text (e.g. `'SAMPLE'`)`watermark_color``string``#000000`Watermark text colour`watermark_opacity``float``0.15`Opacity 0.0–1.0`watermark_rotate``int``-20`Rotation in degrees`watermark_position``string``'center'``'top'` | `'center'` | `'bottom'``watermark_font``int``0`Font size in px, `0` = auto**PNG options** *(same as SVG, with these differences):*

OptionTypeDefaultDescription`color``string|int[]``[0, 0, 0]`Hex string or `[r, g, b]` array`bg``string|int[]``[255, 255, 255]`Hex string, `[r, g, b]` array, or `null` = transparent`font_size``int``3`GD built-in font (1–5)### 1D Watermark

[](#1d-watermark)

The watermark is a semi-transparent diagonal text drawn over the bars — decorative only. Keep `watermark_opacity` ≤ `0.20` to avoid interfering with scanning.

```
$svg = Barcode::type('code128')
    ->data('HF5H65AP')
    ->options([
        'watermark_text'     => 'SAMPLE',
        'watermark_color'    => '#cc0000',
        'watermark_opacity'  => 0.15,
        'watermark_rotate'   => -25,
        'watermark_position' => 'center',
    ])
    ->svg();
```

---

QR Code
-------

[](#qr-code)

### EC Levels

[](#ec-levels)

LevelRecoveryDefaultBest For`L`~7%Clean print environments`M`~15%General use`Q`~25%Printed labels`H`~30%✓Watermarks / damaged environments> **`H` is the default.** It provides the most error recovery and is required when using a center watermark.

### SVG

[](#svg-1)

```
use Laika\Barcode\QrCode;

$svg = QrCode::data('https://example.com')->svg();

header('Content-Type: image/svg+xml');
echo $svg;
```

### PNG *(requires GD)*

[](#png-requires-gd-1)

```
$png = QrCode::data('https://example.com')->png();

header('Content-Type: image/png');
echo $png;
```

### Save to File

[](#save-to-file-1)

```
// SVG
$path = QrCode::data('https://example.com')->save('/var/www/qr/code.svg');

// PNG
$path = QrCode::data('https://example.com')->save('/var/www/qr/code.png');
```

### Options

[](#options-1)

OptionTypeDefaultDescription`module_size``int``8`Pixels per module`margin``int``4`Quiet-zone modules (minimum 4 per QR spec)`color``string``#000000`Dark module colour (hex)`bg``string``#ffffff`Background colour, `''` = transparent```
$svg = QrCode::data('Hello, World!')
    ->ec('Q')
    ->options([
        'module_size' => 10,
        'color'       => '#1a1a2e',
        'bg'          => '#f0f4ff',
    ])
    ->svg();
```

### Center Watermark

[](#center-watermark)

QR codes support a center watermark (text or image/logo) because error-correction redundancy compensates for the obscured modules. Always use **EC=H** (enforced automatically by the watermark helpers).

> Keep `watermark_size` ≤ `0.22` to stay safely within the 30% recovery budget and avoid clipping the finder patterns.

**Text watermark:**

```
// SVG
$svg = QrCode::data('HG6GH5H33')
    ->watermarkText('LAIKA')
    ->svg();

// PNG
$png = QrCode::data('HG6GH5H33')
    ->watermarkText('LAIKA')
    ->png();

// Styled
$svg = QrCode::data('HG6GH5H33')
    ->watermarkText('★', [
        'watermark_size'   => 0.20,
        'watermark_bg'     => '#1a1a2e',
        'watermark_color'  => '#ffffff',
        'watermark_radius' => 50,
        'watermark_font'   => 28,
    ])
    ->svg();
```

**Image/logo watermark:**

```
// From file path
$svg = QrCode::data('HG6GH5H33')
    ->watermarkImage('/path/to/logo.png')
    ->svg();

// From base64 data URI
$svg = QrCode::data('HG6GH5H33')
    ->watermarkImage('data:image/png;base64,...')
    ->svg();

// PNG output with logo
$png = QrCode::data('HG6GH5H33')
    ->watermarkImage('/path/to/logo.png')
    ->png();
```

**Watermark options:**

OptionTypeDefaultDescription`watermark_text``string``''`Text to display in the center box`watermark_image``string``''`File path or `data:image/...;base64,...` URI`watermark_size``float``0.20`Fraction of QR canvas size (max `0.22` recommended)`watermark_bg``string``#ffffff`Background box colour`watermark_color``string``#000000`Text colour`watermark_font``int``0`Font size in px, `0` = auto-fit`watermark_radius``int``4`Corner radius of background box (SVG only)`watermark_padding``int``6`Padding inside background box in px### Raw Matrix

[](#raw-matrix)

```
// Returns bool[][] — true = dark module, false = light
$matrix = QrCode::data('test')->matrix();

foreach ($matrix as $row => $cols) {
    foreach ($cols as $col => $dark) {
        // drive your own renderer
    }
}
```

---

Extending
---------

[](#extending)

### Register a Custom 1D Encoder

[](#register-a-custom-1d-encoder)

```
use Laika\Barcode\Barcode;
use Laika\Barcode\Contracts\BarcodeInterface;

class MyEncoder implements BarcodeInterface
{
    public function encode(string $data): array { /* return bar array */ }
    public function validate(string $data): bool { /* ... */ }
    public function label(string $data): string { return $data; }
}

Barcode::register('myformat', MyEncoder::class);

$svg = Barcode::type('myformat')->data('test')->svg();
```

### Custom 1D Renderer

[](#custom-1d-renderer)

```
use Laika\Barcode\Contracts\RendererInterface;

class HtmlRenderer implements RendererInterface
{
    public function render(array $bars, string $label, array $options = []): string
    {
        $html = '';
        foreach ($bars as $bar) {
            $color = $bar['bar'] ? '#000' : 'transparent';
            $html .= sprintf(
                '',
                $bar['width'] * 2,
                $color
            );
        }
        return $html . '' . htmlspecialchars($label) . '';
    }
}

$html = Barcode::type('code39')
    ->data('HELLO')
    ->renderWith(new HtmlRenderer());
```

---

Running Tests
-------------

[](#running-tests)

```
composer install
./vendor/bin/phpunit
```

---

License
-------

[](#license)

MIT © Laika IT

###  Health Score

37

—

LowBetter than 82% of packages

Maintenance94

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

60d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7272cd554fe8bf859b8450494f244927ee210cd95d516325fda55d33c74e5886?d=identicon)[riyadhtayf](/maintainers/riyadhtayf)

---

Top Contributors

[![laikait](https://avatars.githubusercontent.com/u/100719384?v=4)](https://github.com/laikait "laikait (7 commits)")

---

Tags

barcodephp-barcodephp-barcode-generatorqrcodesvgbarcodepngeancode39code128laika

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[picqer/php-barcode-generator

An easy to use, non-bloated, barcode generator in PHP. Creates SVG, PNG, JPG and HTML images from the most used 1D barcode standards.

1.8k25.5M85](/packages/picqer-php-barcode-generator)[milon/barcode

Barcode generator like Qr Code, PDF417, C39, C39+, C39E, C39E+, C93, S25, S25+, I25, I25+, C128, C128A, C128B, C128C, 2-Digits UPC-Based Extention, 5-Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI (Variation of Plessey code)

1.5k13.3M39](/packages/milon-barcode)[bitgrave/barcode-bundle

provide barcode rendering service into your Symfony2 application.

25444.0k1](/packages/bitgrave-barcode-bundle)[barcode-bakery/barcode-1d

Generates 1D barcodes from a PHP server to a file or HTML document.

10146.1k1](/packages/barcode-bakery-barcode-1d)

PHPackages © 2026

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