PHPackages                             nkamuo/barcode-bundle - 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. [Image &amp; Media](/categories/media)
4. /
5. nkamuo/barcode-bundle

ActiveSymfony-bundle[Image &amp; Media](/categories/media)

nkamuo/barcode-bundle
=====================

A Symfony bundle for barcode generation and processing.

1157PHP

Since Sep 11Pushed 8mo ago1 watchersCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

Barcode Bundle for Symfony and Standalone Applications
======================================================

[](#barcode-bundle-for-symfony-and-standalone-applications)

The **Barcode Bundle** is a flexible and extensible library for generating, processing, encoding, decoding, and formatting barcodes, DataMatrix and QR codes. It is designed to work seamlessly with Symfony applications but can also be used in standalone PHP projects. The library aims to support established standards such as `GS1` and `ANSI` — either out of the box or through third-party and custom extensions.

---

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

[](#table-of-contents)

1. [Introduction](#introduction)
2. [Installation](#installation)
3. [Quick Start](#quick-start)
    - [Using in Symfony](#using-in-symfony)
    - [Using in Standalone PHP Applications](#using-in-standalone-php-applications)
4. [Configuration](#configuration)
    - [Symfony Configuration](#symfony-configuration)
    - [Standalone Configuration](#standalone-configuration)
5. [Components Overview](#components-overview)
    - [Encoders](#encoders)
    - [Decoders](#decoders)
    - [Formatters](#formatters)
    - [Generators](#generators)
    - [Repositories](#repositories)
    - [Processors](#processors)
6. [Extending the Library](#extending-the-library)
7. [Customization](#customization)
8. [Examples](#examples)
9. [Testing](#testing)
10. [Contributing](#contributing)
11. [Credits](#credits)
12. [License](#license)

---

1. Introduction
---------------

[](#1-introduction)

The Barcode Bundle provides a complete solution for working with barcodes and QR codes. It supports:

- Generating barcodes and QR codes.
- Encoding data into various formats.
- Decoding barcodes and QR codes into structured data.
- Formatting barcodes for human-readable or standard-compliant outputs.
- Extending and customizing components like formatters, encoders, decoders, and processors.

Whether you're building a Symfony application or a standalone PHP project, this library is designed to be modular, extensible, and easy to use.

---

2. Installation
---------------

[](#2-installation)

### Requirements

[](#requirements)

- PHP 8.1 or higher.
- Symfony 6.0 or later (for Symfony integration).
- Composer 2.0 or later.

### Install via Composer

[](#install-via-composer)

To install the library, run:

```
composer require nkamuo/barcode-bundle:dev-main
```

For Symfony applications, this will:

- Register the `Nkamuo\Barcode\BarcodeBundle` in `config/bundles.php`.
- Copy the default configuration to `config/packages/barcode.yaml`.

If the bundle is not automatically registered, add it manually:

```
// config/bundles.php
return [
    // ...
    Nkamuo\Barcode\BarcodeBundle::class => ['all' => true],
];
```

---

3. Quick Start
--------------

[](#3-quick-start)

### Using in Symfony

[](#using-in-symfony)

1. **Install the library** (see [Installation](#installation)).
2. **Configure the bundle** in `config/packages/barcode.yaml` (see [Symfony Configuration](#symfony-configuration)).
3. **Use the Barcode Processor**:

```
use Nkamuo\Barcode\BarcodeProcessorInterface;

/** @var BarcodeProcessorInterface $processor */
$processor = $container->get(BarcodeProcessorInterface::class);

// Generate a barcode for Raw-Material
$barcode = $processor->generate([
    'prefix' => 'RM-',
    'standard' => 'CUSTOM'
    ]);
echo $barcode->getValue(); // Outputs: RM-00000001

// Encode the barcode into a QR code
$encoded = $processor->encode($barcode, 'QR', 'PNG');
file_put_contents('barcode.png', $encoded);

// Decode a barcode
$decodedBarcode = $processor->decode('0101234567890128', 'EAN-13');
echo $decodedBarcode->getValue(); // Outputs: 0101234567890128
```

### Using in Standalone PHP Applications

[](#using-in-standalone-php-applications)

1. **Install the library** (see [Installation](#installation)).
2. **Set up the components manually**:

```
require __DIR__ . '/vendor/autoload.php';

use Nkamuo\Barcode\BarcodeProcessor;
use Nkamuo\Barcode\Factory\BarcodeFactory;
use Nkamuo\Barcode\Repository\InMemoryBarcodeRepository;
use Nkamuo\Barcode\Formatter\ChainBarcodeFormatter;
use Nkamuo\Barcode\Encoder\ChainBarcodeEncoder;
use Nkamuo\Barcode\Decoder\ChainBarcodeDecoder;
use Nkamuo\Barcode\Generator\ChainBarcodeGenerator;

// Initialize components
$factory = new BarcodeFactory();
$repository = new InMemoryBarcodeRepository();
$formatter = new ChainBarcodeFormatter([...]); // Add formatters
$encoder = new ChainBarcodeEncoder([...]);     // Add encoders
$decoder = new ChainBarcodeDecoder([...]);     // Add decoders
$generator = new ChainBarcodeGenerator([...]); // Add generators

// Create the processor
$processor = new BarcodeProcessor(
    factory: $factory,
    encoder: $encoder,
    decoder: $decoder,
    generator: $generator,
    formatter: $formatter,
    repository: $repository
);

// Use the processor
$barcode = $processor->generate([
    'prefix' => 'FXT',
    'pad_lenth' => 5,
    ]);
echo $barcode->getValue(); // Output: FXT0000012
```

---

4. Configuration
----------------

[](#4-configuration)

### Symfony Configuration

[](#symfony-configuration)

The default configuration file is located at `config/packages/barcode.yaml`. You can customize the following settings:

```
barcode:
    default_storage: 'in_memory'             # Default storage for barcodes
    enabled_formatters: ['qrcode', 'barcode'] # List of formatters to enable
    processors:
        default:                              # Default processor chain
            encoders: ['basic_encoder']
            decoders: ['default_decoder']
            formatters: ['default_formatter']
```

### Standalone Configuration

[](#standalone-configuration)

For standalone applications, you can configure components manually by instantiating them and passing the required dependencies (see [Quick Start](#using-in-standalone-php-applications)).

---

5. Components Overview
----------------------

[](#5-components-overview)

### [Encoders](docs/encoder.md)

[](#encoders)

Encoders convert `BarcodeInterface` instances into specific formats like QR codes, Data Matrix, or PNG images.
See the [Encoders Documentation](docs/encoder.md) for more details.

### [Decoders](docs/decoder.md)

[](#decoders)

Decoders interpret raw barcode data and convert it into structured `BarcodeInterface` instances.
See the [Decoders Documentation](docs/decoder.md) for more details.

### [Formatters](docs/formatter.md)

[](#formatters)

Formatters provide a way to format barcode data into human-readable or standard-compliant strings.
See the [Formatters Documentation](docs/formatter.md) for more details.

### [Generators](docs/generator.md)

[](#generators)

Generators create new barcodes based on specific contexts or configurations.
See the [Generators Documentation](docs/generator.md) for more details.

### [Repositories](docs/repository.md)

[](#repositories)

Repositories manage the persistence and retrieval of barcodes.
See the [Repositories Documentation](docs/repository.md) for more details.

### [Processors](docs/processor.md)

[](#processors)

Processors orchestrate the interaction between all components, providing a unified interface for barcode operations.
See the [Processors Documentation](docs/processor.md) for more details.

---

6. Extending the Library
------------------------

[](#6-extending-the-library)

The library is designed to be extensible. You can add custom formatters, encoders, decoders, and processors by implementing the respective interfaces.
Refer to the [Extending Documentation](docs) for detailed guides on how to extend each component.

---

7. Customization
----------------

[](#7-customization)

You can customize the library by:

- Adding custom formatters, encoders, decoders, or generators.
- Creating custom processors to handle specific workflows.
- Implementing your own repository for barcode storage (e.g., database-backed).

---

8. Examples
-----------

[](#8-examples)

### Generate and Encode a Barcode

[](#generate-and-encode-a-barcode)

```
$barcode = $processor->generate(['type' => 'GTIN', 'value' => '0123456789012']);
$encoded = $processor->encode($barcode, 'QR', 'PNG');
file_put_contents('barcode.png', $encoded);
```

### Decode a Barcode

[](#decode-a-barcode)

```
$decodedBarcode = $processor->decode(
    data: ']d201034531200000111719112510ABCD1234',
    symbol: null, //DataMatrix
    format: null,
    context: ['standard' => 'GS1']
);
echo $barcode->getAttribute('01');// Output: 03453120000011 [GTIN]
echo $barcode->getAttribute('10');// Output:  ABCD1234 [Batch Number]
echo $barcode->getAttribute('17');// Output:  191125 [Expiry Date]
```

### Format a Barcode

[](#format-a-barcode)

```
$formatted = $formatter->format($barcode, 'LABEL');
echo $formatted;
```

---

9. Testing
----------

[](#9-testing)

Run the tests using PHPUnit:

```
composer install
vendor/bin/phpunit tests/simple
```

---

10. Contributing
----------------

[](#10-contributing)

Contributions are welcome! Please follow these steps:

1. Fork the repository.
2. Create a new branch for your feature or bugfix.
3. Write tests for your changes.
4. Open a pull request.

Feel free to open issues for bugs or feature requests.

---

11. Credits
-----------

[](#11-credits)

This library leverages the following third-party libraries:

- [chillerlan/php-qrcode](https://github.com/chillerlan/php-qrcode)
- [picqer/php-barcode-generator](https://github.com/picqer/php-barcode-generator)
- [endroid/qr-code](https://github.com/endroid/qr-code)

---

12. License
-----------

[](#12-license)

This library is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for more details.

---

Enjoy using the Barcode Bundle! 😊

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance43

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/329bb1f962f7202967c211be87549ce038a95cde9d1ca11d93cfb0874986034d?d=identicon)[nkamuo](/maintainers/nkamuo)

---

Top Contributors

[![nkamuo](https://avatars.githubusercontent.com/u/47611586?v=4)](https://github.com/nkamuo "nkamuo (66 commits)")

---

Tags

barcodebarcode-generatorgs1qrcodeqrcode-generator

### Embed Badge

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

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

###  Alternatives

[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)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

510496.0k23](/packages/bkwld-croppa)[goat1000/svggraph

Generates SVG graphs

132849.6k3](/packages/goat1000-svggraph)[cohensive/embed

Media Embed (for Laravel or as a standalone).

120370.4k](/packages/cohensive-embed)[netresearch/rte-ckeditor-image

Image support in CKEditor for the TYPO3 ecosystem - by Netresearch

63991.3k4](/packages/netresearch-rte-ckeditor-image)[humanmade/tachyon-plugin

Rewrites WordPress image URLs to use Tachyon

87338.5k2](/packages/humanmade-tachyon-plugin)

PHPackages © 2026

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