ayeo/gs1_barcode

Generate GS1-128 standard barcode

1.0.4 2022-04-07 15:55 UTC

This package is auto-updated.

Last update: 2024-10-16 15:46:07 UTC


README

The library generates GS1 barcode. Currently supported formats: GS1 128.

Install

Note that library requires both GD and Free Type extensions installed

composer require ayeo/gs1_barcode:1.0.4

Usage

The simplest example:

use Ayeo\Barcode;

$builder = new Barcode\Builder();
$builder->output('(10)123456(400)11');

This will generate png image using black and white and default font

barcode

Custom barcode:

use Ayeo\Barcode;

$builder = new Barcode\Builder();
$builder->setBarcodeType('gs1-128');
$builder->setFilename('barcode.png');
$builder->setImageFormat('png');
$builder->setWidth(500);
$builder->setHeight(150);
$builder->setFontPath('FreeSans.ttf');
$builder->setFontSize(15);
$builder->setBackgroundColor(255, 255, 255);
$builder->setPaintColor(0, 0, 0);

Finally, you can use the output method to stream the image directly to the web browser.

$builder->output('(10)123456(400)11');

If you want to save the image file, you can use the saveImage method instead.

$builder->saveImage('(10)123456(400)11');

Both output() and saveImage() methods has additional boolean parameters to determine if label should be included on the print. Default value is true.

$builder->output('(10)123456(400)11', $withLabel = false);
$builder->saveImage('(10)123456(400)11', $withLabel = false);

Actually generate the same barcode because all params all set to default values. This shows only available settings

Fluent interface is welcome

use Ayeo\Barcode;

Barcode\Builder::build()->setWidth(600)->setBackgroundColor(100, 100, 100)->output('(10)123456(400)11');

Additional info

  • Supported image formats: png, jpg
  • Barcode must be valid GS1 barcode

Contributing

Everyone is welcome, feel free to join. There is Dockerfile included for ease of developemnt. The image consist of php5.6 with GD and FreeType extensions. It also contains composer and xdebug. To build the image locally use

docker build -t php-gs1 .

Supported identifiers

The goal is to support all existing gs1 application identifiers but at the moment I have added only those I needed. Feel free to add or request some. Full list is here