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

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

panchodp/barcode
================

Generate Code 128 svg barcodes in PHP

v1.0.0(2mo ago)1186↓50%MITPHPPHP ^8.3.0 | ^8.4.0 | ^8.5.0 CI passing

Since Sep 11Pushed 2mo agoCompare

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

READMEChangelog (2)Dependencies (4)Versions (5)Used By (0)

 [![Logo for Barcode](art/barcode.webp)](art/barcode.webp)

[![Php](https://camo.githubusercontent.com/c8d8dad6beb757a2b8acba331d16140813699543b88a37af0a81f20bd35f61de/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332532422d626c7565)](https://camo.githubusercontent.com/c8d8dad6beb757a2b8acba331d16140813699543b88a37af0a81f20bd35f61de/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332532422d626c7565)[![Total Downloads](https://camo.githubusercontent.com/6682b1a2d26987937b5093ca223eac7e24a0401b4c1dd6fd32ef226291f1cd34/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70616e63686f64702f626172636f64653f)](https://camo.githubusercontent.com/6682b1a2d26987937b5093ca223eac7e24a0401b4c1dd6fd32ef226291f1cd34/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70616e63686f64702f626172636f64653f)[![Latest Stable Version](https://camo.githubusercontent.com/fba640dbe42ad91b16e05b816bf249edb7e6dd1cceabb83ef02f84c70e2392c0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70616e63686f64702f626172636f64652e7376673f)](https://packagist.org/packages/panchodp/barcode)[![License](https://camo.githubusercontent.com/5caa455d8debc46fb23abbadb45a733a937f3910a73fc875c2f7820468e1bb54/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e)](https://packagist.org/packages/panchodp/barcode)[![Tests](https://github.com/PanchoDP/barcode/actions/workflows/tests.yml/badge.svg)](https://github.com/PanchoDP/barcode/actions/workflows/tests.yml)

Barcode 128 Generator
=====================

[](#barcode-128-generator)

A simple PHP library to generate Code 128 barcodes in SVG format. Compatible with both **Laravel** and **pure PHP** projects.

Features
--------

[](#features)

✅ **Laravel &amp; Pure PHP Compatible** - Works with both Laravel and standalone PHP projects
✅ **Code 128 Support** - Full support for Code Set A, B and C with automatic selection
✅ **SVG Output** - Scalable vector graphics (no GD dependency)
✅ **Highly Customizable** - Colors, margins, text, dimensions
✅ **Multiple Output Formats** - String, file, base64 data URL
✅ **Auto-discovery** - Laravel 5.5+ automatic service provider registration

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

[](#installation)

### For Laravel Projects

[](#for-laravel-projects)

```
composer require panchodp/barcode
```

The package will be **automatically discovered** by Laravel 5.5+. Optionally publish the config:

```
php artisan vendor:publish --tag=barcode-config
```

### For Pure PHP Projects

[](#for-pure-php-projects)

```
composer require panchodp/barcode
```

Usage
-----

[](#usage)

### Laravel Usage (with Facades)

[](#laravel-usage-with-facades)

```
use Barcode\Facades\Barcode;

// Generate binary pattern
$pattern = Barcode::generate('123456789');

// Generate SVG with quick options
$svg = Barcode::generateWithOptions('123456789', 3, 80);

// Generate SVG with full customization
$svg = Barcode::generateSvg('HELLO123', 'Custom Text', [
    'bar_width' => 3,
    'bar_height' => 80,
    'background_color' => '#f0f0f0',
    'foreground_color' => '#333333',
    'show_text' => true
]);

// Save to file
Barcode::generateSvgFile('ABC123', 'barcode.svg', [
    'bar_width' => 2,
    'bar_height' => 60
]);

// Generate base64 for web
$dataUrl = Barcode::generateSvgBase64('WEB789');
echo '';

// Validate code
if (Barcode::validateCode('123456789')) {
    echo "Valid barcode data";
}
```

### Laravel Usage (with Dependency Injection)

[](#laravel-usage-with-dependency-injection)

```
use Barcode\Barcode;

class BarcodeController extends Controller
{
    public function generate(Barcode $barcode)
    {
        $svg = $barcode->generateSvg('123456789');
        return response($svg)->header('Content-Type', 'image/svg+xml');
    }

    public function download(Barcode $barcode)
    {
        $filename = storage_path('app/barcode.svg');
        $barcode->generateSvgFile('ORDER123', $filename);

        return response()->download($filename);
    }
}
```

### Pure PHP Usage

[](#pure-php-usage)

```
