barcode-bakery/barcode-1d

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

7.0.3 2021-07-30 17:05 UTC

This package is auto-updated.

Last update: 2021-08-30 17:24:05 UTC


README

68747470733a2f2f7777772e626172636f646562616b6572792e636f6d2f696d616765732f4243472d4c6f676f2d53512d4769744875622e737667

Barcode Bakery is library written in PHP, .NET Standard and Node.JS which allows you to generate barcodes on the fly on your server for displaying or saving.

The library has minimal dependencies in each language in order to be supported on a wide variety of web servers.

The library is available for free for non-commercial use; however you must purchase a license if you plan to use it in a commercial environment.

Installation

There are two ways to install our library:

  • With composer, run the following command:
composer require barcode-bakery/barcode-1d

Requirements

  • PHP 7.4+ or PHP8
  • GD2

Example usages

For a full example of how to use each symbology type, visit our API page.

Displaying a Code 128 on the screen

<?php
// Path to the generated autoload file.
require __DIR__ . '/../vendor/autoload.php';

use BarcodeBakery\Common\BCGFontFile;
use BarcodeBakery\Common\BCGColor;
use BarcodeBakery\Common\BCGDrawing;
use BarcodeBakery\Barcode\BCGcode128;

$font = new BCGFontFile(__DIR__ . '/font/Arial.ttf', 18);
$colorBlack = new BCGColor(0, 0, 0);
$colorWhite = new BCGColor(255, 255, 255);

// Barcode Part
$code = new BCGcode128();
$code->setScale(2);
$code->setThickness(30);
$code->setForegroundColor($colorBlack);
$code->setBackgroundColor($colorWhite);
$code->setFont($font);
$code->setStart(null);
$code->setTilde(true);
$code->parse('a123');

// Drawing Part
$drawing = new BCGDrawing($code, $colorWhite);

header('Content-Type: image/png');
$drawing->finish(BCGDrawing::IMG_FORMAT_PNG);

Saving the image to a file

Replace the last lines of the previous code with the following:

// Drawing Part
$drawing = new BCGDrawing($code, $colorWhite);
$drawing->finish(BCGDrawing::IMG_FORMAT_PNG, 'path/to/file.png');

This will generate the following:
68747470733a2f2f7777772e626172636f646562616b6572792e636f6d2f696d616765732f636f64652d3132382d6769746875622e706e67

Supported types

Other libraries available for purchase