antwerpes / barcodes-1d
Library for programmatically creating and rendering barcodes
Requires
- php: ^8.1
- ext-gd: *
- illuminate/collections: ^9.13|^10.0|^11.0
- intervention/image: ^3.6
- meyfa/php-svg: ^0.15.0
- symfony/options-resolver: ^7.1
Requires (Dev)
- chiiya/code-style-php: ^3.0
- phpro/grumphp: ^2.5
- phpunit/phpunit: ^11.2
- symfony/var-dumper: ^7.1
This package is auto-updated.
Last update: 2024-11-07 15:05:55 UTC
README
Barcodes 1D
Barcode generator written in PHP for encoding and rendering most common barcode formats to multiple image output formats.
Features
- Supports most common barcode formats (Code128, EAN, UPC, ...)
- Can render to SVG, PNG, JPG or WEBP using GD
- Images (PNG/JPG/WEBP) may be configured to scale up to any size
- Supports common customization requirements (size, color, text display, font size, background color, font for image rendering, or format-specific options such as guard bars or quiet zones)
Supported barcodes
Installation
Install the package via composer:
composer require antwerpes/barcodes-1d
Usage
Use the Barcodes
factory class to create an encoder and render its output to SVG or a base64-encoded image:
use Antwerpes\Barcodes\Barcodes; use Antwerpes\Barcodes\Enumerators\Format; // SVG $svg = Barcodes::create('12345678', Format::CODE_128); file_put_contents('img.svg', $svg); // Or as an image $image = Barcodes::create('12345678', Format::CODE_128, 'png'); file_put_contents('img.png', base64_decode($image)); // Example for scaled up (4x) WEBP $image = Barcodes::create('12345678', Format::CODE_128, 'webp', [ 'image_scale' => 4, ]); file_put_contents('img.webp', base64_decode($image));
Customization
Check out the options for an overview of all customization options.
Examples
Code 128
Barcodes::create('A12345', Format::CODE_128);
EAN-13
Barcodes::create('5901234123457', Format::EAN_13); Barcodes::create('5901234123457', Format::EAN_13, 'svg', ['flat' => true]); Barcodes::create('5901234123457', Format::EAN_13, 'svg', ['with_quiet_zone' => true]);
EAN-2 / EAN-5 / EAN-8
Barcodes::create('53', Format::EAN_2); Barcodes::create('52495', Format::EAN_5); Barcodes::create('96385074', Format::EAN_8);
UPC-A / UPC-E
Barcodes::create('123456789999', Format::UPC_A); Barcodes::create('01245714', Format::UPC_E); // These also work and will produce the same result Barcodes::create('124571', Format::UPC_E); Barcodes::create('01210000457', Format::UPC_E); Barcodes::create('012100004574', Format::UPC_E);
Codabar
Barcodes::create('A12345B', Format::CODABAR);
Code 11
Barcodes::create('01234-5678', Format::CODE_11);
Code 2 of 5 / Code 2 of 5 Interleaved / ITF-14
Barcodes::create('1234567', Format::CODE_25); Barcodes::create('12345670', Format::CODE_25_INTERLEAVED); Barcodes::create('98765432109213', Format::ITF_14);
Code 39 / Code 93
Barcodes::create('AB12', Format::CODE_39); Barcodes::create('TEST93', Format::CODE_93);
MSI
Barcodes::create('8052', Format::MSI);
Pharmacode
Barcodes::create('1234', Format::PHARMACODE);
Options
Generic options for all barcode formats:
There are additional options for some barcode formats:
Code128
EAN-8 / EAN-13 / UPC-A / UPC-E
Code39
Code39
MSI
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see License File for more information.