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

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

rafsalvioni/zeus-barcode
========================

Provides a Objected-Oriented API to create, draw and manipulate barcode data

2.1.0(7mo ago)29614BSD-3-ClausePHPPHP &gt;=7

Since Jun 7Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/rafsalvioni/zeus-barcode)[ Packagist](https://packagist.org/packages/rafsalvioni/zeus-barcode)[ Docs](https://github.com/rafsalvioni/zeus-barcode)[ RSS](/packages/rafsalvioni-zeus-barcode/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (2)Versions (13)Used By (4)

zeus-barcode
============

[](#zeus-barcode)

Introduction
------------

[](#introduction)

zeus-barcode is a API to create, draw and manage barcode data. Its has many barcode implementations and they could be extended to create other barcodes.

Before use API, you should have in mind the context of API. The API tree are be structured on form below:

### Basic API tree

[](#basic-api-tree)

- **BarcodeInterface**: Identifies all barcodes objects;
    - **ChecksumInterface**: Implemented by barcodes that using checksum on its data;
    - **FixedLengthInterface**: Implemented by barcodes that have a fixed length. Otherwise, it is variable length;
    - **TwoWidthInterface**: Implemented by barcodes that uses only two widths of bars/spaces: wide and narrow;

The most part of these interfaces have been traits to implement some of its methods and abstract classes that implements these interfaces and use these traits.

### Encoders

[](#encoders)

Barcodes can be encoded on different ways. Most barcodes are encoded using bars and spaces. Others uses the height of bars (full and half bar, for example). Now a days, we have implemented two encoders, but, you can implement others implementing **EncoderInterface**.

### Renderers

[](#renderers)

Once a barcode is created, we can draw this barcode in different formats. A renderer is who do this. A renderer should be implement the **RendererInterface**. By default, this package has only the SVG renderer. There are a PDF and Image renderer too in separated packages.

Default usage
-------------

[](#default-usage)

To create a barcode, you have to instantiate the barcode format wanted and gave the data to be encoded. For example, we create a Codabar barcode:

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

use Zeus\Barcode\Codabar;
use Zeus\Barcode\Renderer\SvgRenderer;

$bc = new Codabar('A123456B');
$renderer = new SvgRenderer();
$bc->draw($renderer)->render();
```

The code above will create a Codabar barcode with data "A123456B". This barcode will be drawed using SvgRenderer and the render() method show the result to browser, using especific headers.

All barcodes will be check if the data given can be encoded for them. A barcode exception will be throwed on error.

Calculating barcode checksums
-----------------------------

[](#calculating-barcode-checksums)

Some barcodes needs checksum digits. On these cases, we have two situations:

- We have the full barcode data, with checksum digit. In this case, the barcode class will check the checksum digit given and throws a exception if this checking is false;
- We are creating a new barcode or we don't have full barcode data. In this case, we will inform to barcode class this situation and it will make the checksum digit for us.

For example, we will use the Ean13 format to create a barcode with and without checksum digit:

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

use Zeus\Barcode\Upc\Ean13;

// We don't know the checksum digit, so, we gave false to second argument
$bc = new Ean13('123456789098', false);
echo $bc->getChecksum(); // Prints "2"

// Now we already know the checksum. Let's check it:
$bc = new Ean13('1234567890982', true);
echo $bc->getChecksum(); // Prints "2"

// Let's give a wrong checksum digit
try {
    $bc = new Ean13('1234567890983');
}
catch (\Zeus\Barcode\Exception $ex) {
    echo $ex->getMessage();
}
```

Setting narrow and wide bar/space width
---------------------------------------

[](#setting-narrow-and-wide-barspace-width)

To barcodes thas implements TwoWidthInterface, we can set which width of wide and narrow bar/space. Let's see:

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

use Zeus\Barcode\Code2of5\Interleaved;
use Zeus\Barcode\Renderer\SvgRenderer;

$renderer = new SvgRenderer();

// With default width
$bc1 = new Interleaved('5236589', false);
// Changing widths
$bc2 = clone $bc1;
$bc2->setNarrowWidth(2)->setWideWidth(6);

$renderer->stream($bc1)
         ->stream($bc2)
         ->render();
```

Both widths are in pixels.

Formatting barcode's apresentation
----------------------------------

[](#formatting-barcodes-apresentation)

We can parametrize how our barcode will be showed. There are many options for this. Let's see:

- "barWidth": Width of a bar or space, in renderer's unit. Default 1;
- "barHeight": Height of a bar, in renderer's unit. Default 50;
- "foreColor": Foreground color, as integer. Used to draw bars and text. Default 0x000000 (black);
- "backColor": Background color, as integer. Default 0xffffff (white). If negative, will be transparent;
- "border": Border width, in renderer's unit. Default 0 (no border);
- "showText": Boolean to inform if the text representation of barcode should be showed. Default true;
- "textAlign": Alignment of text. Possible values: "center", "left" and "right". Default "center";
- "textPosition": Position of text. Possible values: "top" and "bottom". Default "bottom";
- "font": Font to write text. Can be a single string or a file path to a font file. If empty, uses default font renderer. Default '';
- "fontSize": Size of font, in points (pt). Default 9;
- "quietZone": Espace that encapsulates the barcode, in renderer's unit. Help to barcode readers. The value defined will be used on left and right. Default 30;

Example:

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

use Zeus\Barcode\Code2of5\Interleaved;
use Zeus\Barcode\Renderer\SvgRenderer;

$renderer = new SvgRenderer();

$bc = new Interleaved('5236589', false);
$bc->backColor = 0xffffaa;
$bc->foreColor = 0x0000ff;
$bc->barwidth  = 2;
$bc->barheight = 150;
$bc->fontsize  = 5;

$bc->draw($renderer)->render();
```

You can use too the scale() method on barcode. This method will resize all dimension options proportionallity.

Managing renderers
------------------

[](#managing-renderers)

We see above how to use renderers on basic way. However, renderers can be setted to do some boring tasks when we use barcodes.

### Styling renderer apresentation

[](#styling-renderer-apresentation)

As barcodes, renderers has some parameters to change how a barcode draw will be done. Are they:

- "offsetTop": Offset from top, in renderer's unit. Default 0;
- "offsetLeft": Offset from left, in renderer's unit. Default 0;
- "backColor": Background color, as integer, used on resize (see "merge" option). Default 0xffffff (white);
- "merge": This is the best option... see below. Boolean value, default false;

Using last example, we can do this:

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

use Zeus\Barcode\Code2of5\Interleaved;
use Zeus\Barcode\Renderer\SvgRenderer;

$renderer = new SvgRenderer();

$bc = new Interleaved('5236589', false);
$bc->backColor = 0xffffaa;
$bc->foreColor = 0x0000ff;
$bc->barwidth  = 2;
$bc->barheight = 150;
$bc->fontsize  = 5;

$renderer->offsetTop = 50;
$renderer->offsetLeft = 50;
$renderer->backColor = 0xababab;

$bc->draw($renderer)->render();
```

### Using renderer's "merge" mode

[](#using-renderers-merge-mode)

By default, renderers draw one barcode at a time. If you draw a barcode and right after you draw another barcode, the resource of first draw will be lost. However, if you set "merge" option to "true", renderer will merge all barcodes draw with him, returning the resource of this merge. On wide/narrow example we can see this when we use the stream() method.

Example:

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

use Zeus\Barcode\Code2of5\Interleaved;
use Zeus\Barcode\Renderer\SvgRenderer;

$renderer = new SvgRenderer();

$bc = new Interleaved('5236589', false);
$bc->backColor = 0xffffaa;
$bc->foreColor = 0x0000ff;
$bc->barwidth  = 2;
$bc->barheight = 150;
$bc->fontsize  = 5;

// Setting render to merge mode
$renderer->merge = true;

$renderer->offsetTop = 50;
$renderer->offsetLeft = 50;
$renderer->backColor = 0xababab;

$bc2 = clone $bc;
$bc2->backColor = 0xffffff;

$bc->draw($renderer); // Draw barcode 1
$renderer->offsetLeft += $bc->getTotalWidth() + 20; // Add a offset
$bc2->draw($renderer);  // Draw barcode 2
$renderer->render(); // Show the result
```

The **RendererInterface::stream()** method do the same of previous example. Its draw a lot of barcodes side by side.

### Using a external resource to render

[](#using-a-external-resource-to-render)

Sometimes, we need to draw a barcode on a external resource. Using the setResource() method, we can define a external resource and barcode will put it, always considering "offsetLeft" and "offsetTop" options. For this, the merge mode will be activated.

Example:

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

use Zeus\Barcode\Code2of5\Interleaved;
use Zeus\Barcode\Renderer\SvgRenderer;

$bc = new Interleaved('5236589', false);

$renderer = new SvgRenderer();
$renderer->setResource("");
$renderer->offsetLeft = 50;
$renderer->offsetTop = 50;

$bc->draw($renderer)->render();
```

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance63

Regular maintenance activity

Popularity14

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity70

Established project with proven stability

 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

Every ~309 days

Recently: every ~848 days

Total

12

Last Release

229d ago

Major Versions

1.1.0 → 2.0.02024-06-29

PHP version history (3 changes)1.0PHP &gt;=5.5 &lt;6

2.0.0PHP ^7

2.1.0PHP &gt;=7

### Community

Maintainers

![](https://www.gravatar.com/avatar/90942747283de521589ccba4428448558de5d667c3e6ad59d2152564ecbd7cb1?d=identicon)[rafsalvioni](/maintainers/rafsalvioni)

---

Top Contributors

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

---

Tags

svgbarcodeEAN13CODABARupccode39MSIcode128Code93Code11ISBNean8ISSNzeusstandard25interleaved25janupcaupceean128itf14

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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.5M88](/packages/picqer-php-barcode-generator)[barcode-bakery/barcode-1d

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

10146.1k1](/packages/barcode-bakery-barcode-1d)[tecnickcom/tc-lib-barcode

PHP library to generate linear and bidimensional barcodes

2957.1M28](/packages/tecnickcom-tc-lib-barcode)[antwerpes/barcodes-1d

Library for programmatically creating and rendering barcodes

258.7k](/packages/antwerpes-barcodes-1d)

PHPackages © 2026

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