ubah ke docker mode
@@ -0,0 +1,27 @@
|
||||
name: Static analysis (phpstan)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: 8.3
|
||||
extensions: mbstring, gd, bcmath, imagick
|
||||
|
||||
- name: Install dependencies
|
||||
run: composer install --prefer-dist --no-progress --no-interaction
|
||||
|
||||
- name: Run analysis
|
||||
run: vendor/bin/phpstan --error-format=github --no-progress
|
||||
@@ -0,0 +1,34 @@
|
||||
name: Unit tests (phpunit)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
php-versions: ['8.2', '8.3', '8.4']
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php-versions }}
|
||||
extensions: mbstring, gd, bcmath, imagick
|
||||
|
||||
- name: Validate composer.json
|
||||
run: composer validate
|
||||
|
||||
- name: Install dependencies
|
||||
run: composer install --prefer-dist --no-progress --no-interaction
|
||||
|
||||
- name: Run test suite
|
||||
run: composer run-script test
|
||||
@@ -0,0 +1,5 @@
|
||||
vendor
|
||||
composer.lock
|
||||
composer.phar
|
||||
.phpunit.result.cache
|
||||
.DS_Store
|
||||
@@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
@@ -0,0 +1,285 @@
|
||||
# PHP Barcode Generator
|
||||
<a href="https://github.com/picqer/php-barcode-generator/actions"><img src="https://github.com/picqer/php-barcode-generator/workflows/phpunit/badge.svg" alt="Build Status"></a>
|
||||
<a href="https://packagist.org/packages/picqer/php-barcode-generator"><img src="https://img.shields.io/packagist/dt/picqer/php-barcode-generator" alt="Total Downloads"></a>
|
||||
<a href="https://packagist.org/packages/picqer/php-barcode-generator"><img src="https://img.shields.io/packagist/v/picqer/php-barcode-generator" alt="Latest Stable Version"></a>
|
||||
|
||||
This is an easy to use, non-bloated, framework independent, barcode generator in PHP. It uses zero(!) composer dependencies and is only a handful of files. Probably the reason that this is the most downloaded barcode generator for PHP on Packagist. ;)
|
||||
|
||||
It creates SVG, PNG, JPG and HTML images, from the most used 1D barcode standards.
|
||||
|
||||
## No support for...
|
||||
- No support for any **2D** barcodes, like QR codes.
|
||||
- We only generate the 'bars' part of a barcode, without text below the barcode. If you want text of the code below the barcode, you could add it later to the output of this package.
|
||||
|
||||
## Installation
|
||||
Install through [composer](https://getcomposer.org/doc/00-intro.md):
|
||||
|
||||
```
|
||||
composer require picqer/php-barcode-generator
|
||||
```
|
||||
|
||||
If you want to generate PNG or JPG images, you need the GD library or Imagick installed on your system as well. For SVG or HTML renders, there are no dependencies.
|
||||
|
||||
## Usage
|
||||
You want a barcode for a specific "type" (for example Code 128 or UPC) in a specific image format (for example PNG or SVG).
|
||||
|
||||
- First, encode the string you want the barcode of into a `Barcode` object with one of the barcode types.
|
||||
- Then, use one of the renderers to render the image of the bars in the `Barcode` object.
|
||||
|
||||
> The "type" is a standard that defines which characters you can encode and which bars represent which character. The most used types are [code 128](https://en.wikipedia.org/wiki/Code_128) and [EAN/UPC](https://en.wikipedia.org/wiki/International_Article_Number). Not all characters can be encoded into each barcode type, and not all barcode scanners can read all types.
|
||||
|
||||
```php
|
||||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
// Make Barcode object of Code128 encoding.
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode128())->getBarcode('081231723897');
|
||||
|
||||
// Output the barcode as HTML in the browser with a HTML Renderer
|
||||
$renderer = new Picqer\Barcode\Renderers\HtmlRenderer();
|
||||
echo $renderer->render($barcode);
|
||||
```
|
||||
|
||||
Will result in this beauty:<br>
|
||||

|
||||
|
||||
Each renderer has their own options. For example, you can set the height, width and color of a PNG:
|
||||
```php
|
||||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
$colorRed = [255, 0, 0];
|
||||
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode128())->getBarcode('081231723897');
|
||||
$renderer = new Picqer\Barcode\Renderers\PngRenderer();
|
||||
$renderer->setForegroundColor($colorRed);
|
||||
|
||||
// Save PNG to the filesystem, with widthFactor 3 (width of the barcode x 3) and height of 50 pixels
|
||||
file_put_contents('barcode.png', $renderer->render($barcode, $barcode->getWidth() * 3, 50));
|
||||
```
|
||||
|
||||
## Image renderers
|
||||
Available image renderers: SVG, PNG, JPG and HTML.
|
||||
|
||||
They all conform to the RendererInterface and have the same `render()` method. Some renderers have extra options as well, via set*() methods.
|
||||
|
||||
### Widths
|
||||
The render() method needs the Barcode object, the width and height. **For JPG/PNG images**, you only get a valid barcode if you give a width that is a factor of the width of the Barcode object. That is why the examples show `$barcode->getWidth() * 2` to make the image 2 times wider in pixels then the width of the barcode data. You *can* give an arbitrary number as width and the image will be scaled as best as possible, but without anti-aliasing, it will not be perfectly valid.
|
||||
|
||||
HTML and SVG renderers can handle any width and height, even floats.
|
||||
|
||||
Here are all the options for each renderer:
|
||||
|
||||
### SVG
|
||||
A vector based SVG image. Gives the best quality to print.
|
||||
```php
|
||||
$renderer = new Picqer\Barcode\Renderers\SvgRenderer();
|
||||
$renderer->setForegroundColor([255, 0, 0]); // Give a color red for the bars, default is black. Give it as 3 times 0-255 values for red, green and blue.
|
||||
$renderer->setBackgroundColor([0, 0, 255]); // Give a color blue for the background, default is transparent. Give it as 3 times 0-255 values for red, green and blue.
|
||||
$renderer->setSvgType($renderer::TYPE_SVG_INLINE); // Changes the output to be used inline inside HTML documents, instead of a standalone SVG image (default)
|
||||
$renderer->setSvgType($renderer::TYPE_SVG_STANDALONE); // If you want to force the default, create a stand alone SVG image
|
||||
|
||||
$renderer->render($barcode, 450.20, 75); // Width and height support floats
|
||||
````
|
||||
|
||||
### PNG + JPG
|
||||
All options for PNG and JPG are the same.
|
||||
```php
|
||||
$renderer = new Picqer\Barcode\Renderers\PngRenderer();
|
||||
$renderer->setForegroundColor([255, 0, 0]); // Give a color for the bars, default is black. Give it as 3 times 0-255 values for red, green and blue.
|
||||
$renderer->setBackgroundColor([0, 255, 255]); // Give a color for the background, default is transparent (in PNG) or white (in JPG). Give it as 3 times 0-255 values for red, green and blue.
|
||||
$renderer->useGd(); // If you have Imagick and GD installed, but want to use GD
|
||||
$renderer->useImagick(); // If you have Imagick and GD installed, but want to use Imagick
|
||||
|
||||
$renderer->render($barcode, 5, 40); // Width factor (how many pixel wide every bar is), and the height in pixels
|
||||
````
|
||||
|
||||
### HTML
|
||||
Gives HTML to use inline in a full HTML document.
|
||||
```php
|
||||
$renderer = new Picqer\Barcode\Renderers\HtmlRenderer();
|
||||
$renderer->setForegroundColor([255, 0, 0]); // Give a color red for the bars, default is black. Give it as 3 times 0-255 values for red, green and blue.
|
||||
$renderer->setBackgroundColor([0, 0, 255]); // Give a color blue for the background, default is transparent. Give it as 3 times 0-255 values for red, green and blue.
|
||||
|
||||
$renderer->render($barcode, 450.20, 75); // Width and height support floats
|
||||
````
|
||||
|
||||
### Dynamic HTML
|
||||
Give HTML here the barcode is using the full width and height, to put inside a container/div that has a fixed size.
|
||||
```php
|
||||
$renderer = new Picqer\Barcode\Renderers\DynamicHtmlRenderer();
|
||||
$renderer->setForegroundColor([255, 0, 0]); // Give a color red for the bars, default is black. Give it as 3 times 0-255 values for red, green and blue.
|
||||
$renderer->setBackgroundColor([0, 0, 255]); // Give a color blue for the background, default is transparent. Give it as 3 times 0-255 values for red, green and blue.
|
||||
|
||||
$renderer->render($barcode);
|
||||
````
|
||||
|
||||
You can put the rendered HTML inside a div like this:
|
||||
```html
|
||||
<div style="width: 400px; height: 75px"><?php echo $renderedBarcode; ?></div>
|
||||
```
|
||||
|
||||
## Accepted barcode types
|
||||
These barcode types are supported. All types support different character sets and some have mandatory lengths. Please see wikipedia for supported chars and lengths per type.
|
||||
|
||||
You can find all supported types in the [src/Types](src/Types) folder.
|
||||
|
||||
Most used types are TYPE_CODE_128 and TYPE_CODE_39. Because of the best scanner support, variable length and most chars supported.
|
||||
|
||||
- TYPE_CODE_32 (italian pharmaceutical code 'MINSAN')
|
||||
- TYPE_CODE_39
|
||||
- TYPE_CODE_39_CHECKSUM
|
||||
- TYPE_CODE_39E
|
||||
- TYPE_CODE_39E_CHECKSUM
|
||||
- TYPE_CODE_93
|
||||
- TYPE_STANDARD_2_5
|
||||
- TYPE_STANDARD_2_5_CHECKSUM
|
||||
- TYPE_INTERLEAVED_2_5
|
||||
- TYPE_INTERLEAVED_2_5_CHECKSUM
|
||||
- TYPE_CODE_128
|
||||
- TYPE_CODE_128_A
|
||||
- TYPE_CODE_128_B
|
||||
- TYPE_CODE_128_C
|
||||
- TYPE_EAN_2
|
||||
- TYPE_EAN_5
|
||||
- TYPE_EAN_8
|
||||
- TYPE_EAN_13
|
||||
- TYPE_ITF14 (Also known as GTIN-14)
|
||||
- TYPE_UPC_A
|
||||
- TYPE_UPC_E
|
||||
- TYPE_MSI
|
||||
- TYPE_MSI_CHECKSUM
|
||||
- TYPE_POSTNET
|
||||
- TYPE_PLANET
|
||||
- TYPE_RMS4CC
|
||||
- TYPE_KIX
|
||||
- TYPE_IMB
|
||||
- TYPE_CODABAR
|
||||
- TYPE_CODE_11
|
||||
- TYPE_PHARMA_CODE
|
||||
- TYPE_PHARMA_CODE_TWO_TRACKS
|
||||
|
||||
[See example images for all supported barcode types](examples.md)
|
||||
|
||||
## A note about PNG and JPG images
|
||||
If you want to use PNG or JPG images, you need to install [Imagick](https://www.php.net/manual/en/intro.imagick.php) or the [GD library](https://www.php.net/manual/en/intro.image.php). This package will use Imagick if that is installed, or fall back to GD. If you have both installed, but you want a specific method, you can use `$renderer->useGd()` or `$renderer->useImagick()` to force your preference.
|
||||
|
||||
## Examples
|
||||
|
||||
### Embedded PNG image in HTML
|
||||
```php
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode128())->getBarcode('081231723897');
|
||||
$renderer = new Picqer\Barcode\Renderers\PngRenderer();
|
||||
echo '<img src="data:image/png;base64,' . base64_encode($renderer->render($barcode, $barcode->getWidth() * 2)) . '">';
|
||||
```
|
||||
|
||||
### Save JPG barcode to disk
|
||||
```php
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCodabar())->getBarcode('081231723897');
|
||||
$renderer = new Picqer\Barcode\Renderers\JpgRenderer();
|
||||
|
||||
file_put_contents('barcode.jpg', $renderer->render($barcode, $barcode->getWidth() * 2));
|
||||
```
|
||||
|
||||
### Oneliner SVG output to disk
|
||||
```php
|
||||
file_put_contents('barcode.svg', (new Picqer\Barcode\Renderers\SvgRenderer())->render((new Picqer\Barcode\Types\TypeKix())->getBarcode('6825ME601')));
|
||||
```
|
||||
|
||||
## Upgrading to v3
|
||||
There is no need to change anything when upgrading from v2 to v3. Above you find the new preferred way of using this library since v3. But the old style still works.
|
||||
|
||||
To give the renderers the same interface, setting colors is now always with an array of RGB colors. If you use the old BarcodeGenerator* classes and use colors with names ('red') or hex codes (#3399ef), these will be converted using the ColorHelper. All hexcodes are supported, but for names of colors only the basic colors are supported.
|
||||
|
||||
If you want to convert to the new style, here is an example:
|
||||
```php
|
||||
// Old style
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
echo $generator->getBarcode('081231723897', $generator::TYPE_CODE_128);
|
||||
|
||||
// New style
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode128())->getBarcode('081231723897');
|
||||
$renderer = new Picqer\Barcode\Renderers\SvgRenderer();
|
||||
echo $renderer->render($barcode);
|
||||
```
|
||||
|
||||
The width in the renderer is now the width of the end result, instead of the widthFactor. If you want to keep dynamic widths, you can get the width of the encoded Barcode and multiply it by the widthFactor to get the same result as before. See here an example for a widthFactor of 2:
|
||||
```php
|
||||
// Old style
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
echo $generator->getBarcode('081231723897', $generator::TYPE_CODE_128, 2. 30);
|
||||
|
||||
// New style
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode128())->getBarcode('081231723897');
|
||||
$renderer = new Picqer\Barcode\Renderers\SvgRenderer();
|
||||
echo $renderer->render($barcode, $barcode->getWidth() * 2, 30);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Previous style generators
|
||||
In version 3 the barcode type encoders and image renderers are completely separate. This makes building your own renderer way easier. The old way was using "generators". Below are the old examples of these generators, which still works in v3 as well.
|
||||
|
||||
### Usage
|
||||
Initiate the barcode generator for the output you want, then call the ->getBarcode() routine as many times as you want.
|
||||
|
||||
```php
|
||||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
// This will output the barcode as HTML output to display in the browser
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorHTML();
|
||||
echo $generator->getBarcode('081231723897', $generator::TYPE_CODE_128);
|
||||
```
|
||||
|
||||
Will result in this beauty:<br>
|
||||

|
||||
|
||||
The `getBarcode()` method accepts the following parameters:
|
||||
- `$barcode` String needed to encode in the barcode
|
||||
- `$type` Type of barcode, use the constants defined in the class
|
||||
- `$widthFactor` Width is based on the length of the data, with this factor you can make the barcode bars wider than default
|
||||
- `$height` The total height of the barcode in pixels
|
||||
- `$foregroundColor` Hex code as string, or array of RGB, of the colors of the bars (the foreground color)
|
||||
|
||||
Example of usage of all parameters:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
$redColor = [255, 0, 0];
|
||||
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorPNG();
|
||||
file_put_contents('barcode.png', $generator->getBarcode('081231723897', $generator::TYPE_CODE_128, 3, 50, $redColor));
|
||||
```
|
||||
|
||||
### Image types
|
||||
```php
|
||||
$generatorSVG = new Picqer\Barcode\BarcodeGeneratorSVG(); // Vector based SVG
|
||||
$generatorPNG = new Picqer\Barcode\BarcodeGeneratorPNG(); // Pixel based PNG
|
||||
$generatorJPG = new Picqer\Barcode\BarcodeGeneratorJPG(); // Pixel based JPG
|
||||
$generatorHTML = new Picqer\Barcode\BarcodeGeneratorHTML(); // Pixel based HTML
|
||||
$generatorHTML = new Picqer\Barcode\BarcodeGeneratorDynamicHTML(); // Vector based HTML
|
||||
```
|
||||
|
||||
#### Embedded PNG image in HTML
|
||||
```php
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorPNG();
|
||||
echo '<img src="data:image/png;base64,' . base64_encode($generator->getBarcode('081231723897', $generator::TYPE_CODE_128)) . '">';
|
||||
```
|
||||
|
||||
#### Save JPG barcode to disk
|
||||
```php
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorJPG();
|
||||
file_put_contents('barcode.jpg', $generator->getBarcode('081231723897', $generator::TYPE_CODABAR));
|
||||
```
|
||||
|
||||
#### Oneliner SVG output to disk
|
||||
```php
|
||||
file_put_contents('barcode.svg', (new Picqer\Barcode\BarcodeGeneratorSVG())->getBarcode('6825ME601', Picqer\Barcode\BarcodeGeneratorSVG::TYPE_KIX));
|
||||
```
|
||||
|
||||
---
|
||||
*The codebase is based on the [TCPDF barcode generator](https://github.com/tecnickcom/TCPDF) by Nicola Asuni. This code is therefor licensed under LGPLv3.*
|
||||
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "picqer/php-barcode-generator",
|
||||
"type": "library",
|
||||
"description": "An easy to use, non-bloated, barcode generator in PHP. Creates SVG, PNG, JPG and HTML images from the most used 1D barcode standards.",
|
||||
"keywords": [ "php", "barcode", "barcode generator", "EAN", "EAN13", "UPC", "Code39", "Code128", "Code93", "Standard 2 of 5", "MSI", "POSTNET", "KIX", "KIXCODE", "CODABAR", "PHARMA", "Code11", "SVG", "PNG", "HTML", "JPG", "JPEG" ],
|
||||
"homepage": "https://github.com/picqer/php-barcode-generator",
|
||||
"license": "LGPL-3.0-or-later",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Casper Bakker",
|
||||
"email": "[email protected]",
|
||||
"homepage": "https://picqer.com"
|
||||
},
|
||||
{
|
||||
"name": "Nicola Asuni",
|
||||
"email": "[email protected]",
|
||||
"homepage": "http://nicolaasuni.tecnick.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^8.2",
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"phpstan/phpstan": "^1.10"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-bcmath": "Barcode IMB (Intelligent Mail Barcode) needs bcmath extension",
|
||||
"ext-gd": "For JPG and PNG generators, GD or Imagick is required",
|
||||
"ext-imagick": "For JPG and PNG generators, GD or Imagick is required"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Picqer\\Barcode\\": "src"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "vendor/bin/phpunit"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
# Examples of supported barcodes
|
||||
|
||||
These are examples of supported barcodes with this library.
|
||||
|
||||
All types can be found in the src/Types directory.
|
||||
|
||||
|
||||
|
||||
### TypeCode39
|
||||
|
||||

|
||||
|
||||
### TypeCode39Checksum
|
||||
|
||||

|
||||
|
||||
### TypeCode39Extended
|
||||
|
||||

|
||||
|
||||
### TypeCode39ExtendedChecksum
|
||||
|
||||

|
||||
|
||||
### TypeCode93
|
||||
|
||||

|
||||
|
||||
### TypeStandard2of5
|
||||
|
||||

|
||||
|
||||
### TypeStandard2of5Checksum
|
||||
|
||||

|
||||
|
||||
### TypeInterleaved25
|
||||
|
||||

|
||||
|
||||
### TypeInterleaved25Checksum
|
||||
|
||||

|
||||
|
||||
### TypeEan13
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
### TypeITF14
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
### TypeCode128
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
### TypeCode128A
|
||||
|
||||

|
||||
|
||||
### TypeCode128B
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
### TypeUpcExtension2
|
||||
|
||||

|
||||
|
||||
### TypeUpcExtension5
|
||||
|
||||

|
||||
|
||||
### TypeEan8
|
||||
|
||||

|
||||
|
||||
### TypeUpcA
|
||||
|
||||

|
||||
|
||||
### TypeUpcE
|
||||
|
||||

|
||||
|
||||
### TypeMsi
|
||||
|
||||

|
||||
|
||||
### TypeMsiChecksum
|
||||
|
||||

|
||||
|
||||
### TypePostnet
|
||||
|
||||

|
||||
|
||||
### TypePlanet
|
||||
|
||||

|
||||
|
||||
### TypeRms4cc
|
||||
|
||||

|
||||
|
||||
### TypeKix
|
||||
|
||||

|
||||
|
||||
### TypeIntelligentMailBarcode
|
||||
|
||||

|
||||
|
||||
### TypeCodabar
|
||||
|
||||

|
||||
|
||||
### TypeCode11
|
||||
|
||||

|
||||
|
||||
### TypePharmacode
|
||||
|
||||

|
||||
|
||||
### TypePharmacodeTwoCode
|
||||
|
||||

|
||||
|
||||
### TypeTelepen
|
||||
|
||||

|
||||
|
||||
### TypeTelepenNumeric
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
*This file is generated by generate-examples.php*
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
require('vendor/autoload.php');
|
||||
require(__DIR__ . '/tests/VerifiedBarcodeTest.php');
|
||||
$verifiedFiles = VerifiedBarcodeTest::$supportedBarcodes;
|
||||
|
||||
$result = [];
|
||||
$result[] = '# Examples of supported barcodes';
|
||||
$result[] = 'These are examples of supported barcodes with this library.';
|
||||
$result[] = 'All types can be found in the src/Types directory.';
|
||||
$result[] = '';
|
||||
|
||||
foreach ($verifiedFiles as $verifiedFile) {
|
||||
$result[] = '### ' . substr($verifiedFile['type'], strrpos($verifiedFile['type'], '\\') + 1);
|
||||
foreach ($verifiedFile['barcodes'] as $barcode) {
|
||||
$result[] = sprintf(
|
||||
'',
|
||||
$barcode,
|
||||
$verifiedFile['type'],
|
||||
Picqer\Barcode\Helpers\StringHelpers::getSafeFilenameFrom($verifiedFile['type'] . '-' . $barcode)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$result[] = '';
|
||||
$result[] = '*This file is generated by generate-examples.php*';
|
||||
|
||||
file_put_contents('examples.md', implode(PHP_EOL . PHP_EOL, $result));
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
require('vendor/autoload.php');
|
||||
|
||||
$svgRenderer = new Picqer\Barcode\Renderers\SvgRenderer();
|
||||
$htmlRenderer = new Picqer\Barcode\Renderers\HtmlRenderer();
|
||||
$dynamicHtmlRenderer = new Picqer\Barcode\Renderers\DynamicHtmlRenderer();
|
||||
|
||||
$typeEncoderEan13 = new \Picqer\Barcode\Types\TypeEan13();
|
||||
$typeEncoderCode128 = new \Picqer\Barcode\Types\TypeCode128();
|
||||
$typeEncoderIMB = new \Picqer\Barcode\Types\TypeIntelligentMailBarcode();
|
||||
|
||||
$barcode = $typeEncoderEan13->getBarcode('081231723897');
|
||||
file_put_contents('tests/verified-files/081231723897-ean13.svg', $svgRenderer->render($barcode, $barcode->getWidth() * 2));
|
||||
file_put_contents('tests/verified-files/081231723897-ean13-fractional-width.svg', $svgRenderer->render($barcode, $barcode->getWidth() * 0.25, 25.75));
|
||||
|
||||
$svgRendererRed = new Picqer\Barcode\Renderers\SvgRenderer();
|
||||
$svgRendererRed->setBackgroundColor([255, 0, 0]);
|
||||
file_put_contents('tests/verified-files/081231723897-ean13-red-background.svg', $svgRendererRed->render($barcode, $barcode->getWidth() * 2));
|
||||
|
||||
$barcode = $typeEncoderCode128->getBarcode('081231723897');
|
||||
file_put_contents('tests/verified-files/081231723897-code128.html', $htmlRenderer->render($barcode, $barcode->getWidth() * 2));
|
||||
$htmlRendererRed = new Picqer\Barcode\Renderers\HtmlRenderer();
|
||||
$htmlRendererRed->setBackgroundColor([255, 0, 0]);
|
||||
file_put_contents('tests/verified-files/081231723897-code128-red-background.html', $htmlRendererRed->render($barcode, $barcode->getWidth() * 2));
|
||||
|
||||
$barcode = $typeEncoderIMB->getBarcode('12345678903');
|
||||
file_put_contents('tests/verified-files/12345678903-imb.html', $htmlRenderer->render($barcode, $barcode->getWidth() * 2));
|
||||
|
||||
$barcode = $typeEncoderCode128->getBarcode('081231723897');
|
||||
file_put_contents('tests/verified-files/081231723897-dynamic-code128.html', $dynamicHtmlRenderer->render($barcode));
|
||||
|
||||
$barcode = $typeEncoderIMB->getBarcode('12345678903');
|
||||
file_put_contents('tests/verified-files/12345678903-dynamic-imb.html', $dynamicHtmlRenderer->render($barcode));
|
||||
|
||||
$barcode = $typeEncoderEan13->getBarcode('0049000004632');
|
||||
file_put_contents('tests/verified-files/0049000004632-ean13.svg', $svgRenderer->render($barcode, $barcode->getWidth() * 2));
|
||||
|
||||
|
||||
// New style of verified files, defined in VerifiedBarcodeTest.php
|
||||
require(__DIR__ . '/tests/VerifiedBarcodeTest.php');
|
||||
$verifiedFiles = VerifiedBarcodeTest::$supportedBarcodes;
|
||||
|
||||
foreach ($verifiedFiles as $verifiedFile) {
|
||||
foreach ($verifiedFile['barcodes'] as $barcodeText) {
|
||||
$barcode = (new $verifiedFile['type']())->getBarcode($barcodeText);
|
||||
$result = $svgRenderer->render($barcode, $barcode->getWidth() * 2);
|
||||
|
||||
file_put_contents('tests/verified-files/' . Picqer\Barcode\Helpers\StringHelpers::getSafeFilenameFrom($verifiedFile['type'] . '-' . $barcodeText) . '.svg', $result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
parameters:
|
||||
paths:
|
||||
- src
|
||||
level: 5
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnError="false" stopOnFailure="false" verbose="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||
<coverage>
|
||||
<include>
|
||||
<directory>./src</directory>
|
||||
</include>
|
||||
</coverage>
|
||||
<testsuites>
|
||||
<testsuite name="Barcode Test Suite">
|
||||
<directory>./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode;
|
||||
|
||||
class Barcode
|
||||
{
|
||||
protected string $barcode;
|
||||
protected int $width = 0;
|
||||
protected int $height = 0;
|
||||
protected array $bars = [];
|
||||
|
||||
public function __construct(string $barcode)
|
||||
{
|
||||
$this->barcode = $barcode;
|
||||
}
|
||||
|
||||
// Add a bar to the barcode, either a bar or a space, at the right side of the barcode
|
||||
public function addBar(BarcodeBar $bar): void
|
||||
{
|
||||
$this->bars[] = $bar;
|
||||
$this->width += $bar->getWidth();
|
||||
$this->height = max($this->height, $bar->getHeight());
|
||||
}
|
||||
|
||||
public function getBarcode(): string
|
||||
{
|
||||
return $this->barcode;
|
||||
}
|
||||
|
||||
public function getWidth(): int
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
public function getHeight(): int
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
|
||||
public function getBars(): array
|
||||
{
|
||||
return $this->bars;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode;
|
||||
|
||||
// Represents a single bar or space in a barcode
|
||||
readonly class BarcodeBar
|
||||
{
|
||||
protected int $width;
|
||||
protected int $height;
|
||||
protected int $positionVertical;
|
||||
protected int $type;
|
||||
|
||||
const TYPE_BAR = 1;
|
||||
const TYPE_SPACING = 0;
|
||||
|
||||
public function __construct(int $width, int $height, bool $drawBar = true, int $positionVertical = 0)
|
||||
{
|
||||
$this->width = $width;
|
||||
$this->height = $height;
|
||||
$this->positionVertical = $positionVertical;
|
||||
$this->type = $drawBar ? self::TYPE_BAR : self::TYPE_SPACING;
|
||||
}
|
||||
|
||||
public function getWidth(): int
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
public function getHeight(): int
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
|
||||
public function getPositionVertical(): int
|
||||
{
|
||||
return $this->positionVertical;
|
||||
}
|
||||
|
||||
public function isBar(): bool
|
||||
{
|
||||
return $this->type === self::TYPE_BAR;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* General PHP Barcode Generator
|
||||
*
|
||||
* @author Casper Bakker - picqer.com
|
||||
* Based on TCPDF Barcode Generator
|
||||
*/
|
||||
|
||||
// Copyright (C) 2002-2015 Nicola Asuni - Tecnick.com LTD
|
||||
//
|
||||
// This file was part of TCPDF software library.
|
||||
//
|
||||
// TCPDF is free software: you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// TCPDF is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the License
|
||||
// along with TCPDF. If not, see
|
||||
// <http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT>.
|
||||
//
|
||||
// See LICENSE.TXT file for more information.
|
||||
|
||||
namespace Picqer\Barcode;
|
||||
|
||||
use Picqer\Barcode\Exceptions\UnknownTypeException;
|
||||
use Picqer\Barcode\Types\TypeCodabar;
|
||||
use Picqer\Barcode\Types\TypeCode11;
|
||||
use Picqer\Barcode\Types\TypeCode128;
|
||||
use Picqer\Barcode\Types\TypeCode128A;
|
||||
use Picqer\Barcode\Types\TypeCode128B;
|
||||
use Picqer\Barcode\Types\TypeCode128C;
|
||||
use Picqer\Barcode\Types\TypeCode32;
|
||||
use Picqer\Barcode\Types\TypeCode39;
|
||||
use Picqer\Barcode\Types\TypeCode39Checksum;
|
||||
use Picqer\Barcode\Types\TypeCode39Extended;
|
||||
use Picqer\Barcode\Types\TypeCode39ExtendedChecksum;
|
||||
use Picqer\Barcode\Types\TypeCode93;
|
||||
use Picqer\Barcode\Types\TypeEan13;
|
||||
use Picqer\Barcode\Types\TypeEan8;
|
||||
use Picqer\Barcode\Types\TypeIntelligentMailBarcode;
|
||||
use Picqer\Barcode\Types\TypeInterface;
|
||||
use Picqer\Barcode\Types\TypeInterleaved25;
|
||||
use Picqer\Barcode\Types\TypeInterleaved25Checksum;
|
||||
use Picqer\Barcode\Types\TypeITF14;
|
||||
use Picqer\Barcode\Types\TypeKix;
|
||||
use Picqer\Barcode\Types\TypeMsi;
|
||||
use Picqer\Barcode\Types\TypeMsiChecksum;
|
||||
use Picqer\Barcode\Types\TypePharmacode;
|
||||
use Picqer\Barcode\Types\TypePharmacodeTwoCode;
|
||||
use Picqer\Barcode\Types\TypePlanet;
|
||||
use Picqer\Barcode\Types\TypePostnet;
|
||||
use Picqer\Barcode\Types\TypeRms4cc;
|
||||
use Picqer\Barcode\Types\TypeStandard2of5;
|
||||
use Picqer\Barcode\Types\TypeStandard2of5Checksum;
|
||||
use Picqer\Barcode\Types\TypeTelepen;
|
||||
use Picqer\Barcode\Types\TypeUpcA;
|
||||
use Picqer\Barcode\Types\TypeUpcE;
|
||||
use Picqer\Barcode\Types\TypeUpcExtension2;
|
||||
use Picqer\Barcode\Types\TypeUpcExtension5;
|
||||
|
||||
abstract class BarcodeGenerator
|
||||
{
|
||||
const TYPE_CODE_32 = 'C32';
|
||||
const TYPE_CODE_39 = 'C39';
|
||||
const TYPE_CODE_39_CHECKSUM = 'C39+';
|
||||
const TYPE_CODE_39E = 'C39E'; // CODE 39 EXTENDED
|
||||
const TYPE_CODE_39E_CHECKSUM = 'C39E+'; // CODE 39 EXTENDED + CHECKSUM
|
||||
const TYPE_CODE_93 = 'C93';
|
||||
const TYPE_STANDARD_2_5 = 'S25';
|
||||
const TYPE_STANDARD_2_5_CHECKSUM = 'S25+';
|
||||
const TYPE_INTERLEAVED_2_5 = 'I25';
|
||||
const TYPE_INTERLEAVED_2_5_CHECKSUM = 'I25+';
|
||||
const TYPE_ITF_14 = 'ITF14';
|
||||
const TYPE_CODE_128 = 'C128';
|
||||
const TYPE_CODE_128_A = 'C128A';
|
||||
const TYPE_CODE_128_B = 'C128B';
|
||||
const TYPE_CODE_128_C = 'C128C';
|
||||
const TYPE_EAN_2 = 'EAN2'; // 2-Digits UPC-Based Extention
|
||||
const TYPE_EAN_5 = 'EAN5'; // 5-Digits UPC-Based Extention
|
||||
const TYPE_EAN_8 = 'EAN8';
|
||||
const TYPE_EAN_13 = 'EAN13';
|
||||
const TYPE_UPC_A = 'UPCA';
|
||||
const TYPE_UPC_E = 'UPCE';
|
||||
const TYPE_MSI = 'MSI'; // MSI (Variation of Plessey code)
|
||||
const TYPE_MSI_CHECKSUM = 'MSI+'; // MSI + CHECKSUM (modulo 11)
|
||||
const TYPE_POSTNET = 'POSTNET';
|
||||
const TYPE_PLANET = 'PLANET';
|
||||
const TYPE_TELEPEN_ALPHA = 'TELEPENALPHA';
|
||||
const TYPE_TELEPEN_NUMERIC = 'TELEPENNUMERIC';
|
||||
const TYPE_RMS4CC = 'RMS4CC'; // RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
|
||||
const TYPE_KIX = 'KIX'; // KIX (Klant index - Customer index)
|
||||
const TYPE_IMB = 'IMB'; // IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
|
||||
const TYPE_CODABAR = 'CODABAR';
|
||||
const TYPE_CODE_11 = 'CODE11';
|
||||
const TYPE_PHARMA_CODE = 'PHARMA';
|
||||
const TYPE_PHARMA_CODE_TWO_TRACKS = 'PHARMA2T';
|
||||
|
||||
/**
|
||||
* @throws UnknownTypeException
|
||||
*/
|
||||
protected function getBarcodeData(string $code, string $type): Barcode
|
||||
{
|
||||
$barcodeDataBuilder = $this->createDataBuilderForType($type);
|
||||
|
||||
return $barcodeDataBuilder->getBarcode($code);
|
||||
}
|
||||
|
||||
protected function createDataBuilderForType(string $type): TypeInterface
|
||||
{
|
||||
switch (strtoupper($type)) {
|
||||
case self::TYPE_CODE_32:
|
||||
return new TypeCode32();
|
||||
|
||||
case self::TYPE_CODE_39:
|
||||
return new TypeCode39();
|
||||
|
||||
case self::TYPE_CODE_39_CHECKSUM:
|
||||
return new TypeCode39Checksum();
|
||||
|
||||
case self::TYPE_CODE_39E:
|
||||
return new TypeCode39Extended();
|
||||
|
||||
case self::TYPE_CODE_39E_CHECKSUM:
|
||||
return new TypeCode39ExtendedChecksum();
|
||||
|
||||
case self::TYPE_CODE_93:
|
||||
return new TypeCode93();
|
||||
|
||||
case self::TYPE_STANDARD_2_5:
|
||||
return new TypeStandard2of5();
|
||||
|
||||
case self::TYPE_STANDARD_2_5_CHECKSUM:
|
||||
return new TypeStandard2of5Checksum();
|
||||
|
||||
case self::TYPE_INTERLEAVED_2_5:
|
||||
return new TypeInterleaved25();
|
||||
|
||||
case self::TYPE_INTERLEAVED_2_5_CHECKSUM:
|
||||
return new TypeInterleaved25Checksum();
|
||||
|
||||
case self::TYPE_ITF_14:
|
||||
return new TypeITF14();
|
||||
|
||||
case self::TYPE_CODE_128:
|
||||
return new TypeCode128();
|
||||
|
||||
case self::TYPE_CODE_128_A:
|
||||
return new TypeCode128A();
|
||||
|
||||
case self::TYPE_CODE_128_B:
|
||||
return new TypeCode128B();
|
||||
|
||||
case self::TYPE_CODE_128_C:
|
||||
return new TypeCode128C();
|
||||
|
||||
case self::TYPE_EAN_2:
|
||||
return new TypeUpcExtension2();
|
||||
|
||||
case self::TYPE_EAN_5:
|
||||
return new TypeUpcExtension5();
|
||||
|
||||
case self::TYPE_EAN_8:
|
||||
return new TypeEan8();
|
||||
|
||||
case self::TYPE_EAN_13:
|
||||
return new TypeEan13();
|
||||
|
||||
case self::TYPE_UPC_A:
|
||||
return new TypeUpcA();
|
||||
|
||||
case self::TYPE_UPC_E:
|
||||
return new TypeUpcE();
|
||||
|
||||
case self::TYPE_MSI:
|
||||
return new TypeMsi();
|
||||
|
||||
case self::TYPE_MSI_CHECKSUM:
|
||||
return new TypeMsiChecksum();
|
||||
|
||||
case self::TYPE_POSTNET:
|
||||
return new TypePostnet();
|
||||
|
||||
case self::TYPE_PLANET:
|
||||
return new TypePlanet();
|
||||
|
||||
case self::TYPE_RMS4CC:
|
||||
return new TypeRms4cc();
|
||||
|
||||
case self::TYPE_KIX:
|
||||
return new TypeKix();
|
||||
|
||||
case self::TYPE_IMB:
|
||||
return new TypeIntelligentMailBarcode();
|
||||
|
||||
case self::TYPE_CODABAR:
|
||||
return new TypeCodabar();
|
||||
|
||||
case self::TYPE_CODE_11:
|
||||
return new TypeCode11();
|
||||
|
||||
case self::TYPE_PHARMA_CODE:
|
||||
return new TypePharmacode();
|
||||
|
||||
case self::TYPE_PHARMA_CODE_TWO_TRACKS:
|
||||
return new TypePharmacodeTwoCode();
|
||||
|
||||
case self::TYPE_TELEPEN_ALPHA:
|
||||
return new TypeTelepen();
|
||||
|
||||
case self::TYPE_TELEPEN_NUMERIC:
|
||||
return new TypeTelepen('numeric');
|
||||
|
||||
}
|
||||
|
||||
throw new UnknownTypeException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode;
|
||||
|
||||
use Picqer\Barcode\Exceptions\UnknownTypeException;
|
||||
use Picqer\Barcode\Helpers\ColorHelper;
|
||||
|
||||
class BarcodeGeneratorDynamicHTML extends BarcodeGenerator
|
||||
{
|
||||
/**
|
||||
* Return an HTML representation of barcode.
|
||||
* This 'dynamic' version uses percentage based widths and heights, resulting in a vector-y qualitative result.
|
||||
*
|
||||
* @param string $barcode code to print
|
||||
* @param BarcodeGenerator::TYPE_* $type (string) type of barcode
|
||||
* @param string $foregroundColor Foreground color for bar elements as '#333' or 'orange' for example (background is transparent).
|
||||
* @return string HTML code.
|
||||
* @throws UnknownTypeException
|
||||
*/
|
||||
public function getBarcode(string $barcode, $type, string $foregroundColor = 'black'): string
|
||||
{
|
||||
$barcodeData = $this->getBarcodeData($barcode, $type);
|
||||
|
||||
$renderer = new \Picqer\Barcode\Renderers\DynamicHtmlRenderer();
|
||||
$renderer->setForegroundColor(ColorHelper::getArrayFromColorString($foregroundColor));
|
||||
|
||||
return $renderer->render($barcodeData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode;
|
||||
|
||||
use Picqer\Barcode\Exceptions\UnknownTypeException;
|
||||
use Picqer\Barcode\Helpers\ColorHelper;
|
||||
|
||||
class BarcodeGeneratorHTML extends BarcodeGenerator
|
||||
{
|
||||
/**
|
||||
* Return an HTML representation of barcode.
|
||||
* This original version uses pixel based widths and heights. Use Dynamic HTML version for better quality representation.
|
||||
*
|
||||
* @param string $barcode code to print
|
||||
* @param BarcodeGenerator::TYPE_* $type (string) type of barcode
|
||||
* @param int $widthFactor Width of a single bar element in pixels.
|
||||
* @param int $height Height of a single bar element in pixels.
|
||||
* @param string $foregroundColor Foreground color for bar elements as '#333' or 'orange' for example (background is transparent).
|
||||
* @return string HTML code.
|
||||
* @throws UnknownTypeException
|
||||
*/
|
||||
public function getBarcode(string $barcode, $type, int $widthFactor = 2, int $height = 30, string $foregroundColor = 'black'): string
|
||||
{
|
||||
$barcodeData = $this->getBarcodeData($barcode, $type);
|
||||
|
||||
$width = round(($barcodeData->getWidth() * $widthFactor), 3);
|
||||
|
||||
$renderer = new \Picqer\Barcode\Renderers\HtmlRenderer();
|
||||
$renderer->setForegroundColor(ColorHelper::getArrayFromColorString($foregroundColor));
|
||||
|
||||
return $renderer->render($barcodeData, $width, $height);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode;
|
||||
|
||||
use Picqer\Barcode\Exceptions\UnknownTypeException;
|
||||
|
||||
class BarcodeGeneratorJPG extends BarcodeGenerator
|
||||
{
|
||||
protected ?bool $useImagick = null;
|
||||
|
||||
/**
|
||||
* Return a PNG image representation of barcode (requires GD or Imagick library).
|
||||
*
|
||||
* @param string $barcode code to print
|
||||
* @param BarcodeGenerator::TYPE_* $type (string) type of barcode
|
||||
* @param int $widthFactor Width of a single bar element in pixels.
|
||||
* @param int $height Height of a single bar element in pixels.
|
||||
* @param array $foregroundColor RGB (0-255) foreground color for bar elements (background is transparent).
|
||||
* @return string image data or false in case of error.
|
||||
* @throws UnknownTypeException
|
||||
*/
|
||||
public function getBarcode(string $barcode, $type, int $widthFactor = 2, int $height = 30, array $foregroundColor = [0, 0, 0]): string
|
||||
{
|
||||
$barcodeData = $this->getBarcodeData($barcode, $type);
|
||||
|
||||
$renderer = new \Picqer\Barcode\Renderers\JpgRenderer();
|
||||
$renderer->setForegroundColor($foregroundColor);
|
||||
|
||||
if (! is_null($this->useImagick)) {
|
||||
if ($this->useImagick) {
|
||||
$renderer->useImagick();
|
||||
} else {
|
||||
$renderer->useGd();
|
||||
}
|
||||
}
|
||||
|
||||
return $renderer->render($barcodeData, $barcodeData->getWidth() * $widthFactor, $height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force the use of Imagick image extension
|
||||
*/
|
||||
public function useImagick(): void
|
||||
{
|
||||
$this->useImagick = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force the use of the GD image library
|
||||
*/
|
||||
public function useGd(): void
|
||||
{
|
||||
$this->useImagick = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode;
|
||||
|
||||
use Picqer\Barcode\Exceptions\UnknownTypeException;
|
||||
|
||||
class BarcodeGeneratorPNG extends BarcodeGenerator
|
||||
{
|
||||
protected ?bool $useImagick = null;
|
||||
|
||||
/**
|
||||
* Return a PNG image representation of barcode (requires GD or Imagick library).
|
||||
*
|
||||
* @param string $barcode code to print
|
||||
* @param BarcodeGenerator::TYPE_* $type (string) type of barcode
|
||||
* @param int $widthFactor Width of a single bar element in pixels.
|
||||
* @param int $height Height of a single bar element in pixels.
|
||||
* @param array $foregroundColor RGB (0-255) foreground color for bar elements (background is transparent).
|
||||
* @return string image data or false in case of error.
|
||||
* @throws UnknownTypeException
|
||||
*/
|
||||
public function getBarcode(string $barcode, $type, int $widthFactor = 2, int $height = 30, array $foregroundColor = [0, 0, 0]): string
|
||||
{
|
||||
$barcodeData = $this->getBarcodeData($barcode, $type);
|
||||
|
||||
$renderer = new \Picqer\Barcode\Renderers\PngRenderer();
|
||||
$renderer->setForegroundColor($foregroundColor);
|
||||
|
||||
if (! is_null($this->useImagick)) {
|
||||
if ($this->useImagick) {
|
||||
$renderer->useImagick();
|
||||
} else {
|
||||
$renderer->useGd();
|
||||
}
|
||||
}
|
||||
|
||||
return $renderer->render($barcodeData, $barcodeData->getWidth() * $widthFactor, $height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force the use of Imagick image extension
|
||||
*/
|
||||
public function useImagick(): void
|
||||
{
|
||||
$this->useImagick = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force the use of the GD image library
|
||||
*/
|
||||
public function useGd(): void
|
||||
{
|
||||
$this->useImagick = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode;
|
||||
|
||||
use Picqer\Barcode\Exceptions\UnknownTypeException;
|
||||
use Picqer\Barcode\Helpers\ColorHelper;
|
||||
|
||||
class BarcodeGeneratorSVG extends BarcodeGenerator
|
||||
{
|
||||
/**
|
||||
* Return a SVG string representation of barcode.
|
||||
*
|
||||
* @param $barcode (string) code to print
|
||||
* @param BarcodeGenerator::TYPE_* $type (string) type of barcode
|
||||
* @param $widthFactor (float) Minimum width of a single bar in user units.
|
||||
* @param $height (float) Height of barcode in user units.
|
||||
* @param $foregroundColor (string) Foreground color (in SVG format) for bar elements (background is transparent).
|
||||
* @return string SVG code.
|
||||
* @public
|
||||
* @throws UnknownTypeException
|
||||
*/
|
||||
public function getBarcode(string $barcode, $type, float $widthFactor = 2, float $height = 30, string $foregroundColor = 'black'): string
|
||||
{
|
||||
$barcodeData = $this->getBarcodeData($barcode, $type);
|
||||
|
||||
$width = round(($barcodeData->getWidth() * $widthFactor), 3);
|
||||
|
||||
$renderer = new \Picqer\Barcode\Renderers\SvgRenderer();
|
||||
$renderer->setForegroundColor(ColorHelper::getArrayFromColorString($foregroundColor));
|
||||
|
||||
return $renderer->render($barcodeData, $width, $height);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Exceptions;
|
||||
|
||||
class BarcodeException extends \Exception {}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Exceptions;
|
||||
|
||||
class InvalidCharacterException extends BarcodeException {}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Exceptions;
|
||||
|
||||
class InvalidCheckDigitException extends BarcodeException {}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Exceptions;
|
||||
|
||||
class InvalidFormatException extends BarcodeException {}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Exceptions;
|
||||
|
||||
class InvalidLengthException extends BarcodeException {}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Exceptions;
|
||||
|
||||
class InvalidOptionException extends BarcodeException {}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Exceptions;
|
||||
|
||||
class UnknownColorException extends BarcodeException {}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Exceptions;
|
||||
|
||||
class UnknownTypeException extends BarcodeException {}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Helpers;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\BarcodeBar;
|
||||
|
||||
/**
|
||||
* Convert binary barcode sequence string to Barcode representation.
|
||||
*/
|
||||
class BinarySequenceConverter
|
||||
{
|
||||
public static function convert(string $code, string $sequence): Barcode
|
||||
{
|
||||
$barcode = new Barcode($code);
|
||||
|
||||
$len = strlen($sequence);
|
||||
$barWidth = 0;
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$barWidth += 1;
|
||||
if (($i == ($len - 1)) || (($i < ($len - 1)) && ($sequence[$i] != $sequence[($i + 1)]))) {
|
||||
if ($sequence[$i] == '1') {
|
||||
$drawBar = true;
|
||||
} else {
|
||||
$drawBar = false;
|
||||
}
|
||||
|
||||
$barcode->addBar(new BarcodeBar($barWidth, 1, $drawBar));
|
||||
$barWidth = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return $barcode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Helpers;
|
||||
|
||||
use Picqer\Barcode\Exceptions\UnknownColorException;
|
||||
|
||||
class ColorHelper
|
||||
{
|
||||
// Convert textual color values, to array of 3 colors 0-255
|
||||
// Can be "red", "#333" or "#009945" styles
|
||||
public static function getArrayFromColorString(string $color): array {
|
||||
if ($color == 'black') {
|
||||
return [0, 0, 0];
|
||||
} elseif ($color == 'white') {
|
||||
return [255, 255, 255];
|
||||
} elseif ($color == 'red') {
|
||||
return [255, 0, 0];
|
||||
} elseif ($color == 'green') {
|
||||
return [0, 255, 0];
|
||||
} elseif ($color == 'blue') {
|
||||
return [0, 0, 255];
|
||||
} elseif ($color == 'yellow') {
|
||||
return [255, 255, 0];
|
||||
}
|
||||
|
||||
// #333 style
|
||||
if (str_starts_with($color, '#') && strlen($color) === 4) {
|
||||
return [
|
||||
hexdec(substr($color, 1, 1) . substr($color, 1, 1)),
|
||||
hexdec(substr($color, 2, 1) . substr($color, 2, 1)),
|
||||
hexdec(substr($color, 3, 1) . substr($color, 3, 1)),
|
||||
];
|
||||
}
|
||||
|
||||
// #009933 style
|
||||
if (str_starts_with($color, '#') && strlen($color) === 7) {
|
||||
return [
|
||||
hexdec(substr($color, 1, 2)),
|
||||
hexdec(substr($color, 2, 2)),
|
||||
hexdec(substr($color, 3, 2)),
|
||||
];
|
||||
}
|
||||
|
||||
throw new UnknownColorException('Only basic string-based colors are supported in v3.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Helpers;
|
||||
|
||||
class StringHelpers
|
||||
{
|
||||
public static function getSafeFilenameFrom(string $className): string {
|
||||
$lastPart = substr($className, strrpos($className, '\\') + 1);
|
||||
|
||||
return preg_replace('/[^a-zA-Z0-9_ \-+]/s', '-', $lastPart);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Renderers;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\BarcodeBar;
|
||||
|
||||
class DynamicHtmlRenderer implements RendererInterface
|
||||
{
|
||||
protected const WIDTH_PRECISION = 6;
|
||||
|
||||
protected array $foregroundColor = [0, 0, 0];
|
||||
protected ?array $backgroundColor = null;
|
||||
|
||||
// Width and height are ignored in this renderer
|
||||
public function render(Barcode $barcode, float $width = 200, float $height = 30): string
|
||||
{
|
||||
$html = '<div style="font-size:0;position:relative;width:100%;height:100%' . ($this->backgroundColor ? ';background-color:rgb(' . implode(',', $this->backgroundColor) . ')' : '') . '">' . PHP_EOL;
|
||||
|
||||
$positionHorizontal = 0;
|
||||
/** @var BarcodeBar $bar */
|
||||
foreach ($barcode->getBars() as $bar) {
|
||||
$barWidth = $bar->getWidth() / $barcode->getWidth() * 100;
|
||||
$barHeight = round(($bar->getHeight() / $barcode->getHeight() * 100), 3);
|
||||
|
||||
if ($bar->isBar() && $barWidth > 0) {
|
||||
$positionVertical = round(($bar->getPositionVertical() / $barcode->getHeight() * 100), 3);
|
||||
|
||||
// draw a vertical bar
|
||||
$html .= '<div style="background-color:rgb(' . implode(',', $this->foregroundColor) . ');width:' . round($barWidth, self::WIDTH_PRECISION) . '%;height:' . $barHeight . '%;position:absolute;left:' . round($positionHorizontal, self::WIDTH_PRECISION) . '%;top:' . $positionVertical . (($positionVertical > 0) ? '%' : '') . '"> </div>' . PHP_EOL;
|
||||
}
|
||||
|
||||
$positionHorizontal += $barWidth;
|
||||
}
|
||||
|
||||
$html .= '</div>' . PHP_EOL;
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function setForegroundColor(array $color): self
|
||||
{
|
||||
$this->foregroundColor = $color;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setBackgroundColor(?array $color): self
|
||||
{
|
||||
$this->backgroundColor = $color;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Renderers;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\BarcodeBar;
|
||||
|
||||
class HtmlRenderer implements RendererInterface
|
||||
{
|
||||
protected array $foregroundColor = [0, 0, 0];
|
||||
protected ?array $backgroundColor = null;
|
||||
|
||||
public function render(Barcode $barcode, float $width = 200, float $height = 30): string
|
||||
{
|
||||
$widthFactor = $width / $barcode->getWidth();
|
||||
|
||||
$html = '<div style="font-size:0;position:relative;width:' . $width . 'px;height:' . ($height) . 'px;' . ($this->backgroundColor ? 'background-color:rgb(' . implode(',', $this->backgroundColor) . ');' : '') . '">' . PHP_EOL;
|
||||
|
||||
$positionHorizontal = 0;
|
||||
/** @var BarcodeBar $bar */
|
||||
foreach ($barcode->getBars() as $bar) {
|
||||
$barWidth = round(($bar->getWidth() * $widthFactor), 3);
|
||||
$barHeight = round(($bar->getHeight() * $height / $barcode->getHeight()), 3);
|
||||
|
||||
if ($bar->isBar() && $barWidth > 0) {
|
||||
$positionVertical = round(($bar->getPositionVertical() * $height / $barcode->getHeight()), 3);
|
||||
|
||||
// draw a vertical bar
|
||||
$html .= '<div style="background-color:rgb(' . implode(',', $this->foregroundColor) . ');width:' . $barWidth . 'px;height:' . $barHeight . 'px;position:absolute;left:' . $positionHorizontal . 'px;top:' . $positionVertical . (($positionVertical > 0) ? 'px' : '') . '"> </div>' . PHP_EOL;
|
||||
}
|
||||
|
||||
$positionHorizontal += $barWidth;
|
||||
}
|
||||
|
||||
$html .= '</div>' . PHP_EOL;
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function setForegroundColor(array $color): self
|
||||
{
|
||||
$this->foregroundColor = $color;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setBackgroundColor(?array $color): self
|
||||
{
|
||||
$this->backgroundColor = $color;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Renderers;
|
||||
|
||||
use Imagick;
|
||||
use ImagickPixel;
|
||||
|
||||
class JpgRenderer extends PngRenderer
|
||||
{
|
||||
protected function createImagickImageObject(int $width, int $height): Imagick
|
||||
{
|
||||
$image = new Imagick();
|
||||
if ($this->backgroundColor !== null) {
|
||||
// Colored background
|
||||
$backgroundColor = new ImagickPixel('rgb(' . implode(',', $this->backgroundColor) . ')');
|
||||
} else {
|
||||
// Use transparent background
|
||||
$backgroundColor = new ImagickPixel('none');
|
||||
}
|
||||
$image->newImage($width, $height, $backgroundColor, 'JPG');
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
protected function generateGdImage($image): void
|
||||
{
|
||||
\imagejpeg($image);
|
||||
\imagedestroy($image);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Renderers;
|
||||
|
||||
use Imagick;
|
||||
use ImagickDraw;
|
||||
use ImagickPixel;
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\BarcodeBar;
|
||||
use Picqer\Barcode\Exceptions\BarcodeException;
|
||||
|
||||
class PngRenderer implements RendererInterface
|
||||
{
|
||||
protected array $foregroundColor = [0, 0, 0];
|
||||
protected ?array $backgroundColor = null;
|
||||
|
||||
protected bool $useImagick;
|
||||
|
||||
/**
|
||||
* @throws BarcodeException
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Auto switch between GD and Imagick based on what is installed
|
||||
if (extension_loaded('imagick')) {
|
||||
$this->useImagick = true;
|
||||
} elseif (function_exists('imagecreate')) {
|
||||
$this->useImagick = false;
|
||||
} else {
|
||||
throw new BarcodeException('Neither gd-lib or imagick are installed!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force the use of Imagick image extension
|
||||
*/
|
||||
public function useImagick(): self
|
||||
{
|
||||
$this->useImagick = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force the use of the GD image library
|
||||
*/
|
||||
public function useGd(): self
|
||||
{
|
||||
$this->useImagick = false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Floats in width and height will be rounded to integers
|
||||
// For best (and valid) result, use a width as a factor of the width of the Barcode object
|
||||
// Example: $width = $barcode->getWidth() * 3
|
||||
public function render(Barcode $barcode, float $width = 200, float $height = 30): string
|
||||
{
|
||||
$width = (int)round($width);
|
||||
$height = (int)round($height);
|
||||
|
||||
$widthFactor = $width / $barcode->getWidth();
|
||||
|
||||
if ($this->useImagick) {
|
||||
$image = $this->createImagickImageObject($width, $height);
|
||||
$imagickBarsShape = new ImagickDraw();
|
||||
$imagickBarsShape->setFillColor(new ImagickPixel('rgb(' . implode(',', $this->foregroundColor) .')'));
|
||||
} else {
|
||||
$image = $this->createGdImageObject($width, $height);
|
||||
$gdForegroundColor = \imagecolorallocate($image, $this->foregroundColor[0], $this->foregroundColor[1], $this->foregroundColor[2]);
|
||||
}
|
||||
|
||||
// print bars
|
||||
$positionHorizontal = 0;
|
||||
/** @var BarcodeBar $bar */
|
||||
foreach ($barcode->getBars() as $bar) {
|
||||
$barWidth = $bar->getWidth() * $widthFactor;
|
||||
|
||||
if ($bar->isBar() && $barWidth > 0) {
|
||||
$y = (int)round(($bar->getPositionVertical() * $height / $barcode->getHeight()));
|
||||
$barHeight = (int)round(($bar->getHeight() * $height / $barcode->getHeight()));
|
||||
|
||||
// draw a vertical bar
|
||||
if ($this->useImagick) {
|
||||
$imagickBarsShape->rectangle((int)round($positionHorizontal), $y, (int)round($positionHorizontal + $barWidth - 1), ($y + $barHeight));
|
||||
} else {
|
||||
\imagefilledrectangle($image, (int)round($positionHorizontal), $y, (int)round($positionHorizontal + $barWidth - 1), ($y + $barHeight), $gdForegroundColor);
|
||||
}
|
||||
}
|
||||
$positionHorizontal += $barWidth;
|
||||
}
|
||||
|
||||
if ($this->useImagick) {
|
||||
$image->drawImage($imagickBarsShape);
|
||||
return $image->getImageBlob();
|
||||
} else {
|
||||
ob_start();
|
||||
$this->generateGdImage($image);
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
|
||||
// Use RGB color definitions, like [0, 0, 0] or [255, 255, 255]
|
||||
public function setForegroundColor(array $color): self
|
||||
{
|
||||
$this->foregroundColor = $color;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Use RGB color definitions, like [0, 0, 0] or [255, 255, 255]
|
||||
// If no color is set, the background will be transparent
|
||||
public function setBackgroundColor(?array $color): self
|
||||
{
|
||||
$this->backgroundColor = $color;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function createGdImageObject(int $width, int $height)
|
||||
{
|
||||
$image = \imagecreate($width, $height);
|
||||
|
||||
if ($this->backgroundColor !== null) {
|
||||
// Colored background
|
||||
$backgroundColor = \imagecolorallocate($image, $this->backgroundColor[0], $this->backgroundColor[1], $this->backgroundColor[2]);
|
||||
\imagefill($image, 0, 0, $backgroundColor);
|
||||
} else {
|
||||
// Use transparent background
|
||||
$backgroundColor = \imagecolorallocate($image, 255, 255, 255);
|
||||
\imagecolortransparent($image, $backgroundColor);
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
protected function createImagickImageObject(int $width, int $height): Imagick
|
||||
{
|
||||
$image = new Imagick();
|
||||
if ($this->backgroundColor !== null) {
|
||||
// Colored background
|
||||
$backgroundColor = new ImagickPixel('rgb(' . implode(',', $this->backgroundColor) . ')');
|
||||
} else {
|
||||
// Use transparent background
|
||||
$backgroundColor = new ImagickPixel('none');
|
||||
}
|
||||
$image->newImage($width, $height, $backgroundColor, 'PNG');
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
protected function generateGdImage($image): void
|
||||
{
|
||||
\imagepng($image);
|
||||
\imagedestroy($image);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Renderers;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
|
||||
interface RendererInterface
|
||||
{
|
||||
public function render(Barcode $barcode, float $width = 200, float $height = 30): string;
|
||||
|
||||
public function setForegroundColor(array $color): self;
|
||||
|
||||
public function setBackgroundColor(?array $color): self;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Renderers;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\BarcodeBar;
|
||||
use Picqer\Barcode\Exceptions\InvalidOptionException;
|
||||
|
||||
class SvgRenderer implements RendererInterface
|
||||
{
|
||||
protected array $foregroundColor = [0, 0, 0];
|
||||
protected ?array $backgroundColor = null;
|
||||
protected string $svgType = self::TYPE_SVG_STANDALONE;
|
||||
|
||||
public const TYPE_SVG_STANDALONE = 'standalone';
|
||||
public const TYPE_SVG_INLINE = 'inline';
|
||||
|
||||
public function render(Barcode $barcode, float $width = 200, float $height = 30): string
|
||||
{
|
||||
$widthFactor = $width / $barcode->getWidth();
|
||||
|
||||
$svg = '';
|
||||
if ($this->svgType === self::TYPE_SVG_STANDALONE) {
|
||||
$svg .= '<?xml version="1.0" standalone="no" ?>' . PHP_EOL;
|
||||
$svg .= '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' . PHP_EOL;
|
||||
}
|
||||
$svg .= '<svg width="' . $width . '" height="' . $height . '" viewBox="0 0 ' . $width . ' ' . $height . '" version="1.1" xmlns="http://www.w3.org/2000/svg">' . PHP_EOL;
|
||||
$svg .= "\t" . '<desc>' . htmlspecialchars($barcode->getBarcode()) . '</desc>' . PHP_EOL;
|
||||
|
||||
// Add background rectangle if backgroundColor is set
|
||||
if ($this->backgroundColor !== null) {
|
||||
$svg .= "\t" . '<rect id="background" width="100%" height="100%" fill="rgb(' . implode(',', $this->backgroundColor) . ')"/>' . PHP_EOL;
|
||||
}
|
||||
|
||||
$svg .= "\t" . '<g id="bars" fill="rgb(' . implode(',', $this->foregroundColor) . ')" stroke="none">' . PHP_EOL;
|
||||
|
||||
// print bars
|
||||
$positionHorizontal = 0;
|
||||
/** @var BarcodeBar $bar */
|
||||
foreach ($barcode->getBars() as $bar) {
|
||||
$barWidth = round(($bar->getWidth() * $widthFactor), 3);
|
||||
$barHeight = round(($bar->getHeight() * $height / $barcode->getHeight()), 3);
|
||||
|
||||
if ($bar->isBar() && $barWidth > 0) {
|
||||
$positionVertical = round(($bar->getPositionVertical() * $height / $barcode->getHeight()), 3);
|
||||
// draw a vertical bar
|
||||
$svg .= "\t\t" . '<rect x="' . $positionHorizontal . '" y="' . $positionVertical . '" width="' . $barWidth . '" height="' . $barHeight . '" />' . PHP_EOL;
|
||||
}
|
||||
|
||||
$positionHorizontal += $barWidth;
|
||||
}
|
||||
|
||||
$svg .= "\t</g>" . PHP_EOL;
|
||||
$svg .= '</svg>' . PHP_EOL;
|
||||
|
||||
return $svg;
|
||||
}
|
||||
|
||||
public function setForegroundColor(array $color): self
|
||||
{
|
||||
$this->foregroundColor = $color;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setBackgroundColor(?array $color): self
|
||||
{
|
||||
$this->backgroundColor = $color;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setSvgType(string $svgType): self
|
||||
{
|
||||
if (! in_array($svgType, [self::TYPE_SVG_INLINE, self::TYPE_SVG_STANDALONE])) {
|
||||
throw new InvalidOptionException();
|
||||
}
|
||||
|
||||
$this->svgType = $svgType;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\BarcodeBar;
|
||||
use Picqer\Barcode\Exceptions\InvalidCharacterException;
|
||||
|
||||
/*
|
||||
* CODABAR barcodes.
|
||||
* Older code often used in library systems, sometimes in blood banks
|
||||
*/
|
||||
|
||||
class TypeCodabar implements TypeInterface
|
||||
{
|
||||
protected array $conversionTable = [
|
||||
'0' => '11111221',
|
||||
'1' => '11112211',
|
||||
'2' => '11121121',
|
||||
'3' => '22111111',
|
||||
'4' => '11211211',
|
||||
'5' => '21111211',
|
||||
'6' => '12111121',
|
||||
'7' => '12112111',
|
||||
'8' => '12211111',
|
||||
'9' => '21121111',
|
||||
'-' => '11122111',
|
||||
'$' => '11221111',
|
||||
':' => '21112121',
|
||||
'/' => '21211121',
|
||||
'.' => '21212111',
|
||||
'+' => '11222221',
|
||||
'A' => '11221211',
|
||||
'B' => '12121121',
|
||||
'C' => '11121221',
|
||||
'D' => '11122211'
|
||||
];
|
||||
|
||||
public function getBarcode(string $code): Barcode
|
||||
{
|
||||
$barcode = new Barcode($code);
|
||||
|
||||
$code = 'A' . strtoupper($code) . 'A';
|
||||
|
||||
for ($i = 0; $i < strlen($code); ++$i) {
|
||||
if (! isset($this->conversionTable[(string)$code[$i]])) {
|
||||
throw new InvalidCharacterException('Char ' . $code[$i] . ' is unsupported');
|
||||
}
|
||||
|
||||
$seq = $this->conversionTable[(string)$code[$i]];
|
||||
for ($j = 0; $j < 8; ++$j) {
|
||||
if (($j % 2) == 0) {
|
||||
$drawBar = true;
|
||||
} else {
|
||||
$drawBar = false;
|
||||
}
|
||||
$barWidth = $seq[$j];
|
||||
$barcode->addBar(new BarcodeBar($barWidth, 1, $drawBar));
|
||||
}
|
||||
}
|
||||
|
||||
return $barcode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\BarcodeBar;
|
||||
use Picqer\Barcode\Exceptions\InvalidCharacterException;
|
||||
|
||||
/*
|
||||
* CODE11 barcodes.
|
||||
* Used primarily for labeling telecommunications equipment
|
||||
*/
|
||||
|
||||
class TypeCode11 implements TypeInterface
|
||||
{
|
||||
protected array $conversionTable = [
|
||||
'0' => '111121',
|
||||
'1' => '211121',
|
||||
'2' => '121121',
|
||||
'3' => '221111',
|
||||
'4' => '112121',
|
||||
'5' => '212111',
|
||||
'6' => '122111',
|
||||
'7' => '111221',
|
||||
'8' => '211211',
|
||||
'9' => '211111',
|
||||
'-' => '112111',
|
||||
'S' => '112211',
|
||||
];
|
||||
|
||||
public function getBarcode(string $code): Barcode
|
||||
{
|
||||
$barcode = new Barcode($code);
|
||||
|
||||
$code .= $this->getCheckDigitC($code);
|
||||
$code .= $this->getCheckDigitK($code);
|
||||
|
||||
$code = 'S' . $code . 'S';
|
||||
|
||||
for ($i = 0; $i < strlen($code); ++$i) {
|
||||
if (! isset($this->conversionTable[$code[$i]])) {
|
||||
throw new InvalidCharacterException('Char ' . $code[$i] . ' is unsupported');
|
||||
}
|
||||
|
||||
$seq = $this->conversionTable[$code[$i]];
|
||||
for ($j = 0; $j < strlen($seq); ++$j) {
|
||||
if (($j % 2) == 0) {
|
||||
$drawBar = true;
|
||||
} else {
|
||||
$drawBar = false;
|
||||
}
|
||||
$barWidth = $seq[$j];
|
||||
|
||||
$barcode->addBar(new BarcodeBar($barWidth, 1, $drawBar));
|
||||
}
|
||||
}
|
||||
|
||||
return $barcode;
|
||||
}
|
||||
|
||||
private function getCheckDigitC(string $code): string
|
||||
{
|
||||
$weight = 1;
|
||||
$checksum = 0;
|
||||
for ($i = (strlen($code) - 1); $i >= 0; --$i) {
|
||||
$digit = $code[$i];
|
||||
if ($digit == '-') {
|
||||
$digitValue = 10;
|
||||
} else {
|
||||
$digitValue = intval($digit);
|
||||
}
|
||||
$checksum += ($digitValue * $weight);
|
||||
++$weight;
|
||||
if ($weight > 10) {
|
||||
$weight = 1;
|
||||
}
|
||||
}
|
||||
$checksum %= 11;
|
||||
if ($checksum == 10) {
|
||||
$checksum = '-';
|
||||
}
|
||||
|
||||
return $checksum;
|
||||
}
|
||||
|
||||
private function getCheckDigitK(string $code): string
|
||||
{
|
||||
if (strlen($code) <= 10) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$weight = 1;
|
||||
$checksum = 0;
|
||||
for ($i = (strlen($code) - 1); $i >= 0; --$i) {
|
||||
$digit = $code[$i];
|
||||
if ($digit == '-') {
|
||||
$digitValue = 10;
|
||||
} else {
|
||||
$digitValue = intval($digit);
|
||||
}
|
||||
$checksum += ($digitValue * $weight);
|
||||
++$weight;
|
||||
if ($weight > 9) {
|
||||
$weight = 1;
|
||||
}
|
||||
}
|
||||
$checksum %= 11;
|
||||
|
||||
return (string)$checksum;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,420 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\BarcodeBar;
|
||||
use Picqer\Barcode\Exceptions\BarcodeException;
|
||||
use Picqer\Barcode\Exceptions\InvalidCharacterException;
|
||||
use Picqer\Barcode\Exceptions\InvalidLengthException;
|
||||
|
||||
/*
|
||||
* C128 barcodes.
|
||||
* Very capable code, excellent density, high reliability; in very wide use world-wide
|
||||
*
|
||||
* @param $code (string) code to represent.
|
||||
* @param $type (string) barcode type: A, B, C or empty for automatic switch (AUTO mode)
|
||||
*/
|
||||
|
||||
class TypeCode128 implements TypeInterface
|
||||
{
|
||||
protected ?string $type = null;
|
||||
|
||||
protected array $conversionTable = [
|
||||
'212222', /* 00 */
|
||||
'222122', /* 01 */
|
||||
'222221', /* 02 */
|
||||
'121223', /* 03 */
|
||||
'121322', /* 04 */
|
||||
'131222', /* 05 */
|
||||
'122213', /* 06 */
|
||||
'122312', /* 07 */
|
||||
'132212', /* 08 */
|
||||
'221213', /* 09 */
|
||||
'221312', /* 10 */
|
||||
'231212', /* 11 */
|
||||
'112232', /* 12 */
|
||||
'122132', /* 13 */
|
||||
'122231', /* 14 */
|
||||
'113222', /* 15 */
|
||||
'123122', /* 16 */
|
||||
'123221', /* 17 */
|
||||
'223211', /* 18 */
|
||||
'221132', /* 19 */
|
||||
'221231', /* 20 */
|
||||
'213212', /* 21 */
|
||||
'223112', /* 22 */
|
||||
'312131', /* 23 */
|
||||
'311222', /* 24 */
|
||||
'321122', /* 25 */
|
||||
'321221', /* 26 */
|
||||
'312212', /* 27 */
|
||||
'322112', /* 28 */
|
||||
'322211', /* 29 */
|
||||
'212123', /* 30 */
|
||||
'212321', /* 31 */
|
||||
'232121', /* 32 */
|
||||
'111323', /* 33 */
|
||||
'131123', /* 34 */
|
||||
'131321', /* 35 */
|
||||
'112313', /* 36 */
|
||||
'132113', /* 37 */
|
||||
'132311', /* 38 */
|
||||
'211313', /* 39 */
|
||||
'231113', /* 40 */
|
||||
'231311', /* 41 */
|
||||
'112133', /* 42 */
|
||||
'112331', /* 43 */
|
||||
'132131', /* 44 */
|
||||
'113123', /* 45 */
|
||||
'113321', /* 46 */
|
||||
'133121', /* 47 */
|
||||
'313121', /* 48 */
|
||||
'211331', /* 49 */
|
||||
'231131', /* 50 */
|
||||
'213113', /* 51 */
|
||||
'213311', /* 52 */
|
||||
'213131', /* 53 */
|
||||
'311123', /* 54 */
|
||||
'311321', /* 55 */
|
||||
'331121', /* 56 */
|
||||
'312113', /* 57 */
|
||||
'312311', /* 58 */
|
||||
'332111', /* 59 */
|
||||
'314111', /* 60 */
|
||||
'221411', /* 61 */
|
||||
'431111', /* 62 */
|
||||
'111224', /* 63 */
|
||||
'111422', /* 64 */
|
||||
'121124', /* 65 */
|
||||
'121421', /* 66 */
|
||||
'141122', /* 67 */
|
||||
'141221', /* 68 */
|
||||
'112214', /* 69 */
|
||||
'112412', /* 70 */
|
||||
'122114', /* 71 */
|
||||
'122411', /* 72 */
|
||||
'142112', /* 73 */
|
||||
'142211', /* 74 */
|
||||
'241211', /* 75 */
|
||||
'221114', /* 76 */
|
||||
'413111', /* 77 */
|
||||
'241112', /* 78 */
|
||||
'134111', /* 79 */
|
||||
'111242', /* 80 */
|
||||
'121142', /* 81 */
|
||||
'121241', /* 82 */
|
||||
'114212', /* 83 */
|
||||
'124112', /* 84 */
|
||||
'124211', /* 85 */
|
||||
'411212', /* 86 */
|
||||
'421112', /* 87 */
|
||||
'421211', /* 88 */
|
||||
'212141', /* 89 */
|
||||
'214121', /* 90 */
|
||||
'412121', /* 91 */
|
||||
'111143', /* 92 */
|
||||
'111341', /* 93 */
|
||||
'131141', /* 94 */
|
||||
'114113', /* 95 */
|
||||
'114311', /* 96 */
|
||||
'411113', /* 97 */
|
||||
'411311', /* 98 */
|
||||
'113141', /* 99 */
|
||||
'114131', /* 100 */
|
||||
'311141', /* 101 */
|
||||
'411131', /* 102 */
|
||||
'211412', /* 103 START A */
|
||||
'211214', /* 104 START B */
|
||||
'211232', /* 105 START C */
|
||||
'233111', /* STOP */
|
||||
'200000' /* END */
|
||||
];
|
||||
|
||||
public function getBarcode(string $code): Barcode
|
||||
{
|
||||
if (strlen(trim($code)) === 0) {
|
||||
throw new InvalidLengthException('You should provide a barcode string.');
|
||||
}
|
||||
|
||||
// ASCII characters for code A (ASCII 00 - 95)
|
||||
$keys_a = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_';
|
||||
$keys_a .= chr(0) . chr(1) . chr(2) . chr(3) . chr(4) . chr(5) . chr(6) . chr(7) . chr(8) . chr(9);
|
||||
$keys_a .= chr(10) . chr(11) . chr(12) . chr(13) . chr(14) . chr(15) . chr(16) . chr(17) . chr(18) . chr(19);
|
||||
$keys_a .= chr(20) . chr(21) . chr(22) . chr(23) . chr(24) . chr(25) . chr(26) . chr(27) . chr(28) . chr(29);
|
||||
$keys_a .= chr(30) . chr(31);
|
||||
|
||||
// ASCII characters for code B (ASCII 32 - 127)
|
||||
$keys_b = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~' . chr(127);
|
||||
|
||||
// special codes
|
||||
$fnc_a = [241 => 102, 242 => 97, 243 => 96, 244 => 101];
|
||||
$fnc_b = [241 => 102, 242 => 97, 243 => 96, 244 => 100];
|
||||
|
||||
// array of symbols
|
||||
$code_data = [];
|
||||
|
||||
// length of the code
|
||||
$len = strlen($code);
|
||||
|
||||
switch (strtoupper($this->type ?? "")) {
|
||||
case 'A':
|
||||
$startid = 103;
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$char = $code[$i];
|
||||
$char_id = ord($char);
|
||||
if (($char_id >= 241) AND ($char_id <= 244)) {
|
||||
$code_data[] = $fnc_a[$char_id];
|
||||
} elseif ($char_id <= 95) {
|
||||
$code_data[] = strpos($keys_a, $char);
|
||||
} else {
|
||||
throw new InvalidCharacterException('Char ' . $char . ' is unsupported');
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'B':
|
||||
$startid = 104;
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$char = $code[$i];
|
||||
$char_id = ord($char);
|
||||
if (($char_id >= 241) AND ($char_id <= 244)) {
|
||||
$code_data[] = $fnc_b[$char_id];
|
||||
} elseif (($char_id >= 32) AND ($char_id <= 127)) {
|
||||
$code_data[] = strpos($keys_b, $char);
|
||||
} else {
|
||||
throw new InvalidCharacterException('Char ' . $char . ' is unsupported');
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
$startid = 105;
|
||||
if (ord($code[0]) == 241) {
|
||||
$code_data[] = 102;
|
||||
$code = substr($code, 1);
|
||||
--$len;
|
||||
}
|
||||
if (($len % 2) != 0) {
|
||||
throw new InvalidLengthException('Length must be even');
|
||||
}
|
||||
for ($i = 0; $i < $len; $i += 2) {
|
||||
$chrnum = $code[$i] . $code[$i + 1];
|
||||
if (preg_match('/([0-9]{2})/', $chrnum) > 0) {
|
||||
$code_data[] = intval($chrnum);
|
||||
} else {
|
||||
throw new InvalidCharacterException();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// split code into sequences
|
||||
$sequence = [];
|
||||
// get numeric sequences (if any)
|
||||
$numseq = [];
|
||||
preg_match_all('/([0-9]{4,})/', $code, $numseq, PREG_OFFSET_CAPTURE);
|
||||
if (! empty($numseq[1])) {
|
||||
$end_offset = 0;
|
||||
foreach ($numseq[1] as $val) {
|
||||
$offset = $val[1];
|
||||
|
||||
// numeric sequence
|
||||
$slen = strlen($val[0]);
|
||||
if (($slen % 2) != 0) {
|
||||
// the length must be even
|
||||
++$offset;
|
||||
$val[0] = substr($val[0], 1);
|
||||
}
|
||||
|
||||
if ($offset > $end_offset) {
|
||||
// non numeric sequence
|
||||
$sequence = array_merge($sequence,
|
||||
$this->get128ABsequence(substr($code, $end_offset, ($offset - $end_offset))));
|
||||
}
|
||||
// numeric sequence fallback
|
||||
$slen = strlen($val[0]);
|
||||
if (($slen % 2) != 0) {
|
||||
// the length must be even
|
||||
--$slen;
|
||||
}
|
||||
$sequence[] = ['C', substr($code, $offset, $slen), $slen];
|
||||
$end_offset = $offset + $slen;
|
||||
}
|
||||
if ($end_offset < $len) {
|
||||
$sequence = array_merge($sequence, $this->get128ABsequence(substr($code, $end_offset)));
|
||||
}
|
||||
} else {
|
||||
// text code (non C mode)
|
||||
$sequence = array_merge($sequence, $this->get128ABsequence($code));
|
||||
}
|
||||
|
||||
// process the sequence
|
||||
foreach ($sequence as $key => $seq) {
|
||||
switch ($seq[0]) {
|
||||
case 'A':
|
||||
if ($key == 0) {
|
||||
$startid = 103;
|
||||
} elseif ($sequence[($key - 1)][0] != 'A') {
|
||||
if (($seq[2] == 1) AND ($key > 0) AND ($sequence[($key - 1)][0] == 'B') AND (! isset($sequence[($key - 1)][3]))) {
|
||||
// single character shift
|
||||
$code_data[] = 98;
|
||||
// mark shift
|
||||
$sequence[$key][3] = true;
|
||||
} elseif (! isset($sequence[($key - 1)][3])) {
|
||||
$code_data[] = 101;
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < $seq[2]; ++$i) {
|
||||
$char = $seq[1][$i];
|
||||
$char_id = ord($char);
|
||||
if (($char_id >= 241) AND ($char_id <= 244)) {
|
||||
$code_data[] = $fnc_a[$char_id];
|
||||
} else {
|
||||
$code_data[] = strpos($keys_a, $char);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'B':
|
||||
if ($key == 0) {
|
||||
$tmpchr = ord($seq[1][0]);
|
||||
if (($seq[2] == 1) AND ($tmpchr >= 241) AND ($tmpchr <= 244) AND isset($sequence[($key + 1)]) AND ($sequence[($key + 1)][0] != 'B')) {
|
||||
switch ($sequence[($key + 1)][0]) {
|
||||
case 'A':
|
||||
{
|
||||
$startid = 103;
|
||||
$sequence[$key][0] = 'A';
|
||||
$code_data[] = $fnc_a[$tmpchr];
|
||||
break;
|
||||
}
|
||||
case 'C':
|
||||
{
|
||||
$startid = 105;
|
||||
$sequence[$key][0] = 'C';
|
||||
$code_data[] = $fnc_a[$tmpchr];
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
$startid = 104;
|
||||
}
|
||||
} elseif ($sequence[($key - 1)][0] != 'B') {
|
||||
if (($seq[2] == 1) AND ($key > 0) AND ($sequence[($key - 1)][0] == 'A') AND (! isset($sequence[($key - 1)][3]))) {
|
||||
// single character shift
|
||||
$code_data[] = 98;
|
||||
// mark shift
|
||||
$sequence[$key][3] = true;
|
||||
} elseif (! isset($sequence[($key - 1)][3])) {
|
||||
$code_data[] = 100;
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < $seq[2]; ++$i) {
|
||||
$char = $seq[1][$i];
|
||||
$char_id = ord($char);
|
||||
if (($char_id >= 241) AND ($char_id <= 244)) {
|
||||
$code_data[] = $fnc_b[$char_id];
|
||||
} else {
|
||||
$code_data[] = strpos($keys_b, $char);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
if ($key == 0) {
|
||||
$startid = 105;
|
||||
} elseif ($sequence[($key - 1)][0] != 'C') {
|
||||
$code_data[] = 99;
|
||||
}
|
||||
for ($i = 0; $i < $seq[2]; $i += 2) {
|
||||
$chrnum = $seq[1][$i] . $seq[1][$i + 1];
|
||||
$code_data[] = intval($chrnum);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new InvalidCharacterException('Do not support different mode then A, B or C.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// calculate check character
|
||||
if (! isset($startid)) {
|
||||
throw new BarcodeException('Could not determine start char for barcode.');
|
||||
}
|
||||
|
||||
$sum = $startid;
|
||||
foreach ($code_data as $key => $val) {
|
||||
$sum += ($val * ($key + 1));
|
||||
}
|
||||
// add check character
|
||||
$code_data[] = ($sum % 103);
|
||||
// add stop sequence
|
||||
$code_data[] = 106;
|
||||
$code_data[] = 107;
|
||||
// add start code at the beginning
|
||||
array_unshift($code_data, $startid);
|
||||
|
||||
// build barcode array
|
||||
$barcode = new Barcode($code);
|
||||
foreach ($code_data as $val) {
|
||||
$seq = $this->conversionTable[$val];
|
||||
for ($j = 0; $j < 6; ++$j) {
|
||||
if (($j % 2) == 0) {
|
||||
$t = true; // bar
|
||||
} else {
|
||||
$t = false; // space
|
||||
}
|
||||
$w = $seq[$j];
|
||||
|
||||
$barcode->addBar(new BarcodeBar($w, 1, $t));
|
||||
}
|
||||
}
|
||||
|
||||
return $barcode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Split text code in A/B sequence for 128 code
|
||||
*
|
||||
* @param $code (string) code to split.
|
||||
* @return array sequence
|
||||
* @protected
|
||||
*/
|
||||
protected function get128ABsequence($code): array
|
||||
{
|
||||
$len = strlen($code);
|
||||
$sequence = [];
|
||||
// get A sequences (if any)
|
||||
$numseq = [];
|
||||
preg_match_all('/([\x00-\x1f])/', $code, $numseq, PREG_OFFSET_CAPTURE);
|
||||
if (empty($numseq[1])) {
|
||||
$end_offset = 0;
|
||||
foreach ($numseq[1] as $val) {
|
||||
$offset = $val[1];
|
||||
if ($offset > $end_offset) {
|
||||
// B sequence
|
||||
$sequence[] = [
|
||||
'B',
|
||||
substr($code, $end_offset, ($offset - $end_offset)),
|
||||
($offset - $end_offset)
|
||||
];
|
||||
}
|
||||
// A sequence
|
||||
$slen = strlen($val[0]);
|
||||
$sequence[] = ['A', substr($code, $offset, $slen), $slen];
|
||||
$end_offset = $offset + $slen;
|
||||
}
|
||||
if ($end_offset < $len) {
|
||||
$sequence[] = ['B', substr($code, $end_offset), ($len - $end_offset)];
|
||||
}
|
||||
} else {
|
||||
// only B sequence
|
||||
$sequence[] = ['B', $code, $len];
|
||||
}
|
||||
|
||||
return $sequence;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
/*
|
||||
* C128 barcodes.
|
||||
* Very capable code, excellent density, high reliability; in very wide use world-wide
|
||||
*
|
||||
* @param $code (string) code to represent.
|
||||
* @param $type (string) barcode type: A, B, C or empty for automatic switch (AUTO mode)
|
||||
*/
|
||||
|
||||
class TypeCode128A extends TypeCode128
|
||||
{
|
||||
protected ?string $type = 'A';
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
/*
|
||||
* C128 barcodes.
|
||||
* Very capable code, excellent density, high reliability; in very wide use world-wide
|
||||
*
|
||||
* @param $code (string) code to represent.
|
||||
* @param $type (string) barcode type: A, B, C or empty for automatic switch (AUTO mode)
|
||||
*/
|
||||
|
||||
class TypeCode128B extends TypeCode128
|
||||
{
|
||||
protected ?string $type = 'B';
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
/*
|
||||
* C128 barcodes.
|
||||
* Very capable code, excellent density, high reliability; in very wide use world-wide
|
||||
*
|
||||
* @param $code (string) code to represent.
|
||||
* @param $type (string) barcode type: A, B, C or empty for automatic switch (AUTO mode)
|
||||
*/
|
||||
|
||||
class TypeCode128C extends TypeCode128
|
||||
{
|
||||
protected ?string $type = 'C';
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\Exceptions\InvalidCharacterException;
|
||||
use Picqer\Barcode\Exceptions\InvalidCheckDigitException;
|
||||
use Picqer\Barcode\Exceptions\InvalidLengthException;
|
||||
|
||||
/*
|
||||
* CODE 32 - italian pharmaceutical
|
||||
* General-purpose code in very wide use world-wide
|
||||
*/
|
||||
class TypeCode32 extends TypeCode39
|
||||
{
|
||||
protected array $conversionTable32 = [
|
||||
'0' => '0',
|
||||
'1' => '1',
|
||||
'2' => '2',
|
||||
'3' => '3',
|
||||
'4' => '4',
|
||||
'5' => '5',
|
||||
'6' => '6',
|
||||
'7' => '7',
|
||||
'8' => '8',
|
||||
'9' => '9',
|
||||
'10' => 'B',
|
||||
'11' => 'C',
|
||||
'12' => 'D',
|
||||
'13' => 'F',
|
||||
'14' => 'G',
|
||||
'15' => 'H',
|
||||
'16' => 'J',
|
||||
'17' => 'K',
|
||||
'18' => 'L',
|
||||
'19' => 'M',
|
||||
'20' => 'N',
|
||||
'21' => 'P',
|
||||
'22' => 'Q',
|
||||
'23' => 'R',
|
||||
'24' => 'S',
|
||||
'25' => 'T',
|
||||
'26' => 'U',
|
||||
'27' => 'V',
|
||||
'28' => 'W',
|
||||
'29' => 'X',
|
||||
'30' => 'Y',
|
||||
'31' => 'Z'
|
||||
];
|
||||
|
||||
public function getBarcode(string $code): Barcode
|
||||
{
|
||||
// Validate code 32.
|
||||
$stringLength = strlen($code);
|
||||
|
||||
for ($i = 0; $i < $stringLength; ++$i) {
|
||||
if (!is_numeric($code[$i])) {
|
||||
throw new InvalidCharacterException('Character "' . $code[$i] . '" is not supported.');
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare code 32.
|
||||
$code = str_pad($code, 8, '0', STR_PAD_LEFT);
|
||||
$checksumDigit = $this->checksum_code32(substr($code, 0, 8));
|
||||
$stringLength = max($stringLength, 8);
|
||||
|
||||
if ($stringLength === 8) {
|
||||
$code .= $checksumDigit;
|
||||
++$stringLength;
|
||||
}
|
||||
if ($stringLength !== 9) {
|
||||
throw new InvalidLengthException('Only a code consisting of no more than 9 numbers is supported.');
|
||||
}
|
||||
if ($code[8] !== $checksumDigit) {
|
||||
throw new InvalidCheckDigitException('Provided checksum digit is wrong for provided code.');
|
||||
}
|
||||
|
||||
// Convert code 32 into code 39.
|
||||
$code39 = '';
|
||||
$codeElab = $code;
|
||||
|
||||
for ($e = 5; $e >= 0; --$e) {
|
||||
$code39 .= $this->conversionTable32[intval($codeElab / pow(32, $e))];
|
||||
$codeElab = $codeElab % pow(32, $e);
|
||||
}
|
||||
|
||||
// Return barcode data for code 39.
|
||||
return parent::getBarcode($code39);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate CODE 32 checksum (modulo 10).
|
||||
*
|
||||
* @param string $code code to represent.
|
||||
* @return string char checksum.
|
||||
* @protected
|
||||
*/
|
||||
protected function checksum_code32(string $code): string
|
||||
{
|
||||
$checksum = 0;
|
||||
|
||||
foreach (str_split($code) as $i => $c) {
|
||||
if (0 === $i % 2) {
|
||||
$checksum += (int)$c;
|
||||
} else {
|
||||
$c = 2 * (int)$c;
|
||||
$checksum += (int)floor($c / 10) + ($c % 10);
|
||||
}
|
||||
}
|
||||
|
||||
return (string)($checksum % 10);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,330 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\BarcodeBar;
|
||||
use Picqer\Barcode\Exceptions\InvalidCharacterException;
|
||||
use Picqer\Barcode\Exceptions\InvalidLengthException;
|
||||
|
||||
/*
|
||||
* CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
|
||||
* General-purpose code in very wide use world-wide
|
||||
*/
|
||||
|
||||
class TypeCode39 implements TypeInterface
|
||||
{
|
||||
protected bool $extended = false;
|
||||
protected bool $checksum = false;
|
||||
|
||||
protected array $conversionTable = [
|
||||
'0' => '111331311',
|
||||
'1' => '311311113',
|
||||
'2' => '113311113',
|
||||
'3' => '313311111',
|
||||
'4' => '111331113',
|
||||
'5' => '311331111',
|
||||
'6' => '113331111',
|
||||
'7' => '111311313',
|
||||
'8' => '311311311',
|
||||
'9' => '113311311',
|
||||
'A' => '311113113',
|
||||
'B' => '113113113',
|
||||
'C' => '313113111',
|
||||
'D' => '111133113',
|
||||
'E' => '311133111',
|
||||
'F' => '113133111',
|
||||
'G' => '111113313',
|
||||
'H' => '311113311',
|
||||
'I' => '113113311',
|
||||
'J' => '111133311',
|
||||
'K' => '311111133',
|
||||
'L' => '113111133',
|
||||
'M' => '313111131',
|
||||
'N' => '111131133',
|
||||
'O' => '311131131',
|
||||
'P' => '113131131',
|
||||
'Q' => '111111333',
|
||||
'R' => '311111331',
|
||||
'S' => '113111331',
|
||||
'T' => '111131331',
|
||||
'U' => '331111113',
|
||||
'V' => '133111113',
|
||||
'W' => '333111111',
|
||||
'X' => '131131113',
|
||||
'Y' => '331131111',
|
||||
'Z' => '133131111',
|
||||
'-' => '131111313',
|
||||
'.' => '331111311',
|
||||
' ' => '133111311',
|
||||
'$' => '131313111',
|
||||
'/' => '131311131',
|
||||
'+' => '131113131',
|
||||
'%' => '111313131',
|
||||
'*' => '131131311',
|
||||
];
|
||||
|
||||
public function getBarcode(string $code): Barcode
|
||||
{
|
||||
if (strlen(trim($code)) === 0) {
|
||||
throw new InvalidLengthException('You should provide a barcode string.');
|
||||
}
|
||||
|
||||
if ($this->extended) {
|
||||
// extended mode
|
||||
$code = $this->encode_code39_ext($code);
|
||||
}
|
||||
|
||||
if ($this->checksum) {
|
||||
// checksum
|
||||
$code .= $this->checksum_code39($code);
|
||||
}
|
||||
|
||||
// add start and stop codes
|
||||
$code = '*' . $code . '*';
|
||||
|
||||
$barcode = new Barcode($code);
|
||||
|
||||
for ($i = 0; $i < strlen($code); ++$i) {
|
||||
$char = $code[$i];
|
||||
if (! isset($this->conversionTable[$char])) {
|
||||
throw new InvalidCharacterException('Char ' . $char . ' is unsupported');
|
||||
}
|
||||
|
||||
for ($j = 0; $j < 9; ++$j) {
|
||||
if (($j % 2) == 0) {
|
||||
$drawBar = true;
|
||||
} else {
|
||||
$drawBar = false;
|
||||
}
|
||||
$barWidth = $this->conversionTable[$char][$j];
|
||||
$barcode->addBar(new BarcodeBar($barWidth, 1, $drawBar));
|
||||
}
|
||||
|
||||
// inter character gap
|
||||
$barcode->addBar(new BarcodeBar(1, 1, false));
|
||||
}
|
||||
|
||||
return $barcode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encode a string to be used for CODE 39 Extended mode.
|
||||
*
|
||||
* @param string $code code to represent.
|
||||
* @return string encoded string.
|
||||
* @protected
|
||||
* @throws InvalidCharacterException
|
||||
*/
|
||||
protected function encode_code39_ext(string $code): string
|
||||
{
|
||||
$encode = [
|
||||
chr(0) => '%U',
|
||||
chr(1) => '$A',
|
||||
chr(2) => '$B',
|
||||
chr(3) => '$C',
|
||||
chr(4) => '$D',
|
||||
chr(5) => '$E',
|
||||
chr(6) => '$F',
|
||||
chr(7) => '$G',
|
||||
chr(8) => '$H',
|
||||
chr(9) => '$I',
|
||||
chr(10) => '$J',
|
||||
chr(11) => '$K',
|
||||
chr(12) => '$L',
|
||||
chr(13) => '$M',
|
||||
chr(14) => '$N',
|
||||
chr(15) => '$O',
|
||||
chr(16) => '$P',
|
||||
chr(17) => '$Q',
|
||||
chr(18) => '$R',
|
||||
chr(19) => '$S',
|
||||
chr(20) => '$T',
|
||||
chr(21) => '$U',
|
||||
chr(22) => '$V',
|
||||
chr(23) => '$W',
|
||||
chr(24) => '$X',
|
||||
chr(25) => '$Y',
|
||||
chr(26) => '$Z',
|
||||
chr(27) => '%A',
|
||||
chr(28) => '%B',
|
||||
chr(29) => '%C',
|
||||
chr(30) => '%D',
|
||||
chr(31) => '%E',
|
||||
chr(32) => ' ',
|
||||
chr(33) => '/A',
|
||||
chr(34) => '/B',
|
||||
chr(35) => '/C',
|
||||
chr(36) => '/D',
|
||||
chr(37) => '/E',
|
||||
chr(38) => '/F',
|
||||
chr(39) => '/G',
|
||||
chr(40) => '/H',
|
||||
chr(41) => '/I',
|
||||
chr(42) => '/J',
|
||||
chr(43) => '/K',
|
||||
chr(44) => '/L',
|
||||
chr(45) => '-',
|
||||
chr(46) => '.',
|
||||
chr(47) => '/O',
|
||||
chr(48) => '0',
|
||||
chr(49) => '1',
|
||||
chr(50) => '2',
|
||||
chr(51) => '3',
|
||||
chr(52) => '4',
|
||||
chr(53) => '5',
|
||||
chr(54) => '6',
|
||||
chr(55) => '7',
|
||||
chr(56) => '8',
|
||||
chr(57) => '9',
|
||||
chr(58) => '/Z',
|
||||
chr(59) => '%F',
|
||||
chr(60) => '%G',
|
||||
chr(61) => '%H',
|
||||
chr(62) => '%I',
|
||||
chr(63) => '%J',
|
||||
chr(64) => '%V',
|
||||
chr(65) => 'A',
|
||||
chr(66) => 'B',
|
||||
chr(67) => 'C',
|
||||
chr(68) => 'D',
|
||||
chr(69) => 'E',
|
||||
chr(70) => 'F',
|
||||
chr(71) => 'G',
|
||||
chr(72) => 'H',
|
||||
chr(73) => 'I',
|
||||
chr(74) => 'J',
|
||||
chr(75) => 'K',
|
||||
chr(76) => 'L',
|
||||
chr(77) => 'M',
|
||||
chr(78) => 'N',
|
||||
chr(79) => 'O',
|
||||
chr(80) => 'P',
|
||||
chr(81) => 'Q',
|
||||
chr(82) => 'R',
|
||||
chr(83) => 'S',
|
||||
chr(84) => 'T',
|
||||
chr(85) => 'U',
|
||||
chr(86) => 'V',
|
||||
chr(87) => 'W',
|
||||
chr(88) => 'X',
|
||||
chr(89) => 'Y',
|
||||
chr(90) => 'Z',
|
||||
chr(91) => '%K',
|
||||
chr(92) => '%L',
|
||||
chr(93) => '%M',
|
||||
chr(94) => '%N',
|
||||
chr(95) => '%O',
|
||||
chr(96) => '%W',
|
||||
chr(97) => '+A',
|
||||
chr(98) => '+B',
|
||||
chr(99) => '+C',
|
||||
chr(100) => '+D',
|
||||
chr(101) => '+E',
|
||||
chr(102) => '+F',
|
||||
chr(103) => '+G',
|
||||
chr(104) => '+H',
|
||||
chr(105) => '+I',
|
||||
chr(106) => '+J',
|
||||
chr(107) => '+K',
|
||||
chr(108) => '+L',
|
||||
chr(109) => '+M',
|
||||
chr(110) => '+N',
|
||||
chr(111) => '+O',
|
||||
chr(112) => '+P',
|
||||
chr(113) => '+Q',
|
||||
chr(114) => '+R',
|
||||
chr(115) => '+S',
|
||||
chr(116) => '+T',
|
||||
chr(117) => '+U',
|
||||
chr(118) => '+V',
|
||||
chr(119) => '+W',
|
||||
chr(120) => '+X',
|
||||
chr(121) => '+Y',
|
||||
chr(122) => '+Z',
|
||||
chr(123) => '%P',
|
||||
chr(124) => '%Q',
|
||||
chr(125) => '%R',
|
||||
chr(126) => '%S',
|
||||
chr(127) => '%T'
|
||||
];
|
||||
|
||||
$code_ext = '';
|
||||
for ($i = 0; $i < strlen($code); ++$i) {
|
||||
if (ord($code[$i]) > 127) {
|
||||
throw new InvalidCharacterException('Only supports till char 127');
|
||||
}
|
||||
|
||||
$code_ext .= $encode[$code[$i]];
|
||||
}
|
||||
|
||||
return $code_ext;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate CODE 39 checksum (modulo 43).
|
||||
*
|
||||
* @param string $code code to represent.
|
||||
* @return string char checksum.
|
||||
* @protected
|
||||
*/
|
||||
protected function checksum_code39($code)
|
||||
{
|
||||
$chars = [
|
||||
'0',
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
'4',
|
||||
'5',
|
||||
'6',
|
||||
'7',
|
||||
'8',
|
||||
'9',
|
||||
'A',
|
||||
'B',
|
||||
'C',
|
||||
'D',
|
||||
'E',
|
||||
'F',
|
||||
'G',
|
||||
'H',
|
||||
'I',
|
||||
'J',
|
||||
'K',
|
||||
'L',
|
||||
'M',
|
||||
'N',
|
||||
'O',
|
||||
'P',
|
||||
'Q',
|
||||
'R',
|
||||
'S',
|
||||
'T',
|
||||
'U',
|
||||
'V',
|
||||
'W',
|
||||
'X',
|
||||
'Y',
|
||||
'Z',
|
||||
'-',
|
||||
'.',
|
||||
' ',
|
||||
'$',
|
||||
'/',
|
||||
'+',
|
||||
'%'
|
||||
];
|
||||
|
||||
$checksum = 0;
|
||||
for ($index = 0; $index < strlen($code); ++$index) {
|
||||
$charPosition = array_keys($chars, $code[$index]);
|
||||
$checksum += $charPosition[0];
|
||||
}
|
||||
$checksumIndex = ($checksum % 43);
|
||||
|
||||
return $chars[$checksumIndex];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
/*
|
||||
* CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
|
||||
* General-purpose code in very wide use world-wide
|
||||
*/
|
||||
|
||||
class TypeCode39Checksum extends TypeCode39
|
||||
{
|
||||
protected bool $extended = false;
|
||||
protected bool $checksum = true;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
/*
|
||||
* CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
|
||||
* General-purpose code in very wide use world-wide
|
||||
*/
|
||||
|
||||
class TypeCode39Extended extends TypeCode39
|
||||
{
|
||||
protected bool $extended = true;
|
||||
protected bool $checksum = false;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
/*
|
||||
* CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
|
||||
* General-purpose code in very wide use world-wide
|
||||
*/
|
||||
|
||||
class TypeCode39ExtendedChecksum extends TypeCode39
|
||||
{
|
||||
protected bool $extended = true;
|
||||
protected bool $checksum = true;
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\BarcodeBar;
|
||||
use Picqer\Barcode\Exceptions\InvalidCharacterException;
|
||||
|
||||
/*
|
||||
* CODE 93 - USS-93
|
||||
* Compact code similar to Code 39
|
||||
*
|
||||
* reference: https://en.wikipedia.org/wiki/Code_93#Full_ASCII_Code_93
|
||||
*/
|
||||
|
||||
class TypeCode93 implements TypeInterface
|
||||
{
|
||||
protected array $conversionTable = [
|
||||
48 => '131112', // 0
|
||||
49 => '111213', // 1
|
||||
50 => '111312', // 2
|
||||
51 => '111411', // 3
|
||||
52 => '121113', // 4
|
||||
53 => '121212', // 5
|
||||
54 => '121311', // 6
|
||||
55 => '111114', // 7
|
||||
56 => '131211', // 8
|
||||
57 => '141111', // 9
|
||||
65 => '211113', // A
|
||||
66 => '211212', // B
|
||||
67 => '211311', // C
|
||||
68 => '221112', // D
|
||||
69 => '221211', // E
|
||||
70 => '231111', // F
|
||||
71 => '112113', // G
|
||||
72 => '112212', // H
|
||||
73 => '112311', // I
|
||||
74 => '122112', // J
|
||||
75 => '132111', // K
|
||||
76 => '111123', // L
|
||||
77 => '111222', // M
|
||||
78 => '111321', // N
|
||||
79 => '121122', // O
|
||||
80 => '131121', // P
|
||||
81 => '212112', // Q
|
||||
82 => '212211', // R
|
||||
83 => '211122', // S
|
||||
84 => '211221', // T
|
||||
85 => '221121', // U
|
||||
86 => '222111', // V
|
||||
87 => '112122', // W
|
||||
88 => '112221', // X
|
||||
89 => '122121', // Y
|
||||
90 => '123111', // Z
|
||||
45 => '121131', // -
|
||||
46 => '311112', // .
|
||||
32 => '311211', //
|
||||
36 => '321111', // $
|
||||
47 => '112131', // /
|
||||
43 => '113121', // +
|
||||
37 => '211131', // %
|
||||
97 => '121221', // ($)
|
||||
98 => '312111', // (%)
|
||||
99 => '311121', // (/)
|
||||
100 => '122211', // (+)
|
||||
42 => '111141', // start-stop
|
||||
];
|
||||
|
||||
public function getBarcode(string $code): Barcode
|
||||
{
|
||||
$encode = [
|
||||
chr(0) => 'bU',
|
||||
chr(1) => 'aA',
|
||||
chr(2) => 'aB',
|
||||
chr(3) => 'aC',
|
||||
chr(4) => 'aD',
|
||||
chr(5) => 'aE',
|
||||
chr(6) => 'aF',
|
||||
chr(7) => 'aG',
|
||||
chr(8) => 'aH',
|
||||
chr(9) => 'aI',
|
||||
chr(10) => 'aJ',
|
||||
chr(11) => 'aK',
|
||||
chr(12) => 'aL',
|
||||
chr(13) => 'aM',
|
||||
chr(14) => 'aN',
|
||||
chr(15) => 'aO',
|
||||
chr(16) => 'aP',
|
||||
chr(17) => 'aQ',
|
||||
chr(18) => 'aR',
|
||||
chr(19) => 'aS',
|
||||
chr(20) => 'aT',
|
||||
chr(21) => 'aU',
|
||||
chr(22) => 'aV',
|
||||
chr(23) => 'aW',
|
||||
chr(24) => 'aX',
|
||||
chr(25) => 'aY',
|
||||
chr(26) => 'aZ',
|
||||
chr(27) => 'bA',
|
||||
chr(28) => 'bB',
|
||||
chr(29) => 'bC',
|
||||
chr(30) => 'bD',
|
||||
chr(31) => 'bE',
|
||||
chr(32) => ' ',
|
||||
chr(33) => 'cA',
|
||||
chr(34) => 'cB',
|
||||
chr(35) => 'cC',
|
||||
chr(36) => '$',
|
||||
chr(37) => '%',
|
||||
chr(38) => 'cF',
|
||||
chr(39) => 'cG',
|
||||
chr(40) => 'cH',
|
||||
chr(41) => 'cI',
|
||||
chr(42) => 'cJ',
|
||||
chr(43) => '+',
|
||||
chr(44) => 'cL',
|
||||
chr(45) => '-',
|
||||
chr(46) => '.',
|
||||
chr(47) => '/',
|
||||
chr(48) => '0',
|
||||
chr(49) => '1',
|
||||
chr(50) => '2',
|
||||
chr(51) => '3',
|
||||
chr(52) => '4',
|
||||
chr(53) => '5',
|
||||
chr(54) => '6',
|
||||
chr(55) => '7',
|
||||
chr(56) => '8',
|
||||
chr(57) => '9',
|
||||
chr(58) => 'cZ',
|
||||
chr(59) => 'bF',
|
||||
chr(60) => 'bG',
|
||||
chr(61) => 'bH',
|
||||
chr(62) => 'bI',
|
||||
chr(63) => 'bJ',
|
||||
chr(64) => 'bV',
|
||||
chr(65) => 'A',
|
||||
chr(66) => 'B',
|
||||
chr(67) => 'C',
|
||||
chr(68) => 'D',
|
||||
chr(69) => 'E',
|
||||
chr(70) => 'F',
|
||||
chr(71) => 'G',
|
||||
chr(72) => 'H',
|
||||
chr(73) => 'I',
|
||||
chr(74) => 'J',
|
||||
chr(75) => 'K',
|
||||
chr(76) => 'L',
|
||||
chr(77) => 'M',
|
||||
chr(78) => 'N',
|
||||
chr(79) => 'O',
|
||||
chr(80) => 'P',
|
||||
chr(81) => 'Q',
|
||||
chr(82) => 'R',
|
||||
chr(83) => 'S',
|
||||
chr(84) => 'T',
|
||||
chr(85) => 'U',
|
||||
chr(86) => 'V',
|
||||
chr(87) => 'W',
|
||||
chr(88) => 'X',
|
||||
chr(89) => 'Y',
|
||||
chr(90) => 'Z',
|
||||
chr(91) => 'bK',
|
||||
chr(92) => 'bL',
|
||||
chr(93) => 'bM',
|
||||
chr(94) => 'bN',
|
||||
chr(95) => 'bO',
|
||||
chr(96) => 'bW',
|
||||
chr(97) => 'dA',
|
||||
chr(98) => 'dB',
|
||||
chr(99) => 'dC',
|
||||
chr(100) => 'dD',
|
||||
chr(101) => 'dE',
|
||||
chr(102) => 'dF',
|
||||
chr(103) => 'dG',
|
||||
chr(104) => 'dH',
|
||||
chr(105) => 'dI',
|
||||
chr(106) => 'dJ',
|
||||
chr(107) => 'dK',
|
||||
chr(108) => 'dL',
|
||||
chr(109) => 'dM',
|
||||
chr(110) => 'dN',
|
||||
chr(111) => 'dO',
|
||||
chr(112) => 'dP',
|
||||
chr(113) => 'dQ',
|
||||
chr(114) => 'dR',
|
||||
chr(115) => 'dS',
|
||||
chr(116) => 'dT',
|
||||
chr(117) => 'dU',
|
||||
chr(118) => 'dV',
|
||||
chr(119) => 'dW',
|
||||
chr(120) => 'dX',
|
||||
chr(121) => 'dY',
|
||||
chr(122) => 'dZ',
|
||||
chr(123) => 'bP',
|
||||
chr(124) => 'bQ',
|
||||
chr(125) => 'bR',
|
||||
chr(126) => 'bS',
|
||||
chr(127) => 'bT',
|
||||
];
|
||||
|
||||
$code_ext = '';
|
||||
$clen = strlen($code);
|
||||
for ($i = 0; $i < $clen; ++$i) {
|
||||
if (ord($code[$i]) > 127) {
|
||||
throw new InvalidCharacterException('Only supports till char 127');
|
||||
}
|
||||
$code_ext .= $encode[$code[$i]];
|
||||
}
|
||||
|
||||
// checksum
|
||||
$code_ext .= $this->checksum_code93($code_ext);
|
||||
|
||||
// add start and stop codes
|
||||
$code = '*' . $code_ext . '*';
|
||||
|
||||
$barcode = new Barcode($code);
|
||||
|
||||
for ($i = 0; $i < strlen($code); ++$i) {
|
||||
$char = ord($code[$i]);
|
||||
if (! isset($this->conversionTable[$char])) {
|
||||
throw new InvalidCharacterException('Char ' . $char . ' is unsupported');
|
||||
}
|
||||
|
||||
for ($j = 0; $j < 6; ++$j) {
|
||||
if (($j % 2) == 0) {
|
||||
$drawBar = true;
|
||||
} else {
|
||||
$drawBar = false;
|
||||
}
|
||||
$barWidth = $this->conversionTable[$char][$j];
|
||||
|
||||
$barcode->addBar(new BarcodeBar($barWidth, 1, $drawBar));
|
||||
}
|
||||
}
|
||||
|
||||
$barcode->addBar(new BarcodeBar(1, 1, true));
|
||||
|
||||
return $barcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate CODE 93 checksum (modulo 47).
|
||||
*
|
||||
* @param $code (string) code to represent.
|
||||
* @return string checksum code.
|
||||
* @protected
|
||||
*/
|
||||
protected function checksum_code93(string $code): string
|
||||
{
|
||||
$chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '-', '.', ' ', '$', '/', '+', '%', 'a', 'b', 'c', 'd'];
|
||||
|
||||
// calculate check digit C
|
||||
$codeLength = strlen($code);
|
||||
$weight = 1;
|
||||
$checksum = 0;
|
||||
for ($i = ($codeLength - 1); $i >= 0; --$i) {
|
||||
$charIndex = array_keys($chars, $code[$i]);
|
||||
$checksum += ($charIndex[0] * $weight);
|
||||
++$weight;
|
||||
if ($weight > 20) {
|
||||
$weight = 1;
|
||||
}
|
||||
}
|
||||
$checksumC = $checksum % 47;
|
||||
$checkDigitC = $chars[$checksumC];
|
||||
$codeWithC = $code . $checkDigitC;
|
||||
|
||||
// calculate check digit K
|
||||
$weight = 1;
|
||||
$checksum = 0;
|
||||
for ($i = $codeLength; $i >= 0; --$i) {
|
||||
$charIndex = array_keys($chars, $codeWithC[$i]);
|
||||
$checksum += ($charIndex[0] * $weight);
|
||||
++$weight;
|
||||
if ($weight > 15) {
|
||||
$weight = 1;
|
||||
}
|
||||
}
|
||||
$checksumK = $checksum % 47;
|
||||
$checkDigitK = $chars[$checksumK];
|
||||
|
||||
return $checkDigitC . $checkDigitK;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
/*
|
||||
* EAN13 and UPC-A barcodes.
|
||||
* EAN13: European Article Numbering international retail product code
|
||||
* UPC-A: Universal product code seen on almost all retail products in the USA and Canada
|
||||
* UPC-E: Short version of UPC symbol
|
||||
*
|
||||
* @param $code (string) code to represent.
|
||||
* @param $len (string) barcode type: 6 = UPC-E, 8 = EAN8, 13 = EAN13, 12 = UPC-A
|
||||
*/
|
||||
|
||||
class TypeEan13 extends TypeEanUpcBase
|
||||
{
|
||||
protected int $length = 13;
|
||||
protected bool $upca = false;
|
||||
protected bool $upce = false;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
/*
|
||||
* EAN13 and UPC-A barcodes.
|
||||
* EAN13: European Article Numbering international retail product code
|
||||
* UPC-A: Universal product code seen on almost all retail products in the USA and Canada
|
||||
* UPC-E: Short version of UPC symbol
|
||||
*
|
||||
* @param $code (string) code to represent.
|
||||
* @param $len (string) barcode type: 6 = UPC-E, 8 = EAN8, 13 = EAN13, 12 = UPC-A
|
||||
*/
|
||||
|
||||
class TypeEan8 extends TypeEanUpcBase
|
||||
{
|
||||
protected int $length = 8;
|
||||
protected bool $upca = false;
|
||||
protected bool $upce = false;
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\BarcodeBar;
|
||||
use Picqer\Barcode\Exceptions\InvalidCharacterException;
|
||||
use Picqer\Barcode\Exceptions\InvalidCheckDigitException;
|
||||
use Picqer\Barcode\Exceptions\InvalidLengthException;
|
||||
|
||||
/*
|
||||
* EAN13 and UPC-A barcodes.
|
||||
* EAN13: European Article Numbering international retail product code
|
||||
* UPC-A: Universal product code seen on almost all retail products in the USA and Canada
|
||||
* UPC-E: Short version of UPC symbol
|
||||
*
|
||||
* @param $code (string) code to represent.
|
||||
* @param $len (string) barcode type: 6 = UPC-E, 8 = EAN8, 13 = EAN13, 12 = UPC-A
|
||||
*/
|
||||
|
||||
abstract class TypeEanUpcBase implements TypeInterface
|
||||
{
|
||||
protected int $length = 13;
|
||||
protected bool $upca = false;
|
||||
protected bool $upce = false;
|
||||
|
||||
public function getBarcode(string $code): Barcode
|
||||
{
|
||||
if (strlen(trim($code)) === 0) {
|
||||
throw new InvalidLengthException('You should provide a barcode string.');
|
||||
}
|
||||
|
||||
$length = $this->length;
|
||||
|
||||
$dataLength = $length - 1;
|
||||
|
||||
// Add zero padding in front
|
||||
$code = str_pad($code, $dataLength, '0', STR_PAD_LEFT);
|
||||
|
||||
$checksumDigit = $this->calculateChecksumDigit($code);
|
||||
|
||||
if (strlen($code) == $dataLength) {
|
||||
$code .= $checksumDigit;
|
||||
} elseif ($checksumDigit !== intval($code[$dataLength])) {
|
||||
// If length of given barcode is same as final length, barcode is including checksum
|
||||
// Make sure that checksum is the same as we calculated
|
||||
throw new InvalidCheckDigitException();
|
||||
}
|
||||
|
||||
if ($this->upca || $this->upce) {
|
||||
$code = '0' . $code;
|
||||
++$length;
|
||||
}
|
||||
|
||||
if ($this->upce) {
|
||||
// convert UPC-A to UPC-E
|
||||
$tmp = substr($code, 4, 3);
|
||||
if (($tmp == '000') OR ($tmp == '100') OR ($tmp == '200')) {
|
||||
// manufacturer code ends in 000, 100, or 200
|
||||
$upce_code = substr($code, 2, 2) . substr($code, 9, 3) . substr($code, 4, 1);
|
||||
} else {
|
||||
$tmp = substr($code, 5, 2);
|
||||
if ($tmp == '00') {
|
||||
// manufacturer code ends in 00
|
||||
$upce_code = substr($code, 2, 3) . substr($code, 10, 2) . '3';
|
||||
} else {
|
||||
$tmp = substr($code, 6, 1);
|
||||
if ($tmp == '0') {
|
||||
// manufacturer code ends in 0
|
||||
$upce_code = substr($code, 2, 4) . substr($code, 11, 1) . '4';
|
||||
} else {
|
||||
// manufacturer code does not end in zero
|
||||
$upce_code = substr($code, 2, 5) . substr($code, 11, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Convert digits to bars
|
||||
$codes = [
|
||||
'A' => [ // left odd parity
|
||||
'0' => '0001101',
|
||||
'1' => '0011001',
|
||||
'2' => '0010011',
|
||||
'3' => '0111101',
|
||||
'4' => '0100011',
|
||||
'5' => '0110001',
|
||||
'6' => '0101111',
|
||||
'7' => '0111011',
|
||||
'8' => '0110111',
|
||||
'9' => '0001011'
|
||||
],
|
||||
'B' => [ // left even parity
|
||||
'0' => '0100111',
|
||||
'1' => '0110011',
|
||||
'2' => '0011011',
|
||||
'3' => '0100001',
|
||||
'4' => '0011101',
|
||||
'5' => '0111001',
|
||||
'6' => '0000101',
|
||||
'7' => '0010001',
|
||||
'8' => '0001001',
|
||||
'9' => '0010111'
|
||||
],
|
||||
'C' => [ // right
|
||||
'0' => '1110010',
|
||||
'1' => '1100110',
|
||||
'2' => '1101100',
|
||||
'3' => '1000010',
|
||||
'4' => '1011100',
|
||||
'5' => '1001110',
|
||||
'6' => '1010000',
|
||||
'7' => '1000100',
|
||||
'8' => '1001000',
|
||||
'9' => '1110100'
|
||||
]
|
||||
];
|
||||
|
||||
$parities = [
|
||||
'0' => ['A', 'A', 'A', 'A', 'A', 'A'],
|
||||
'1' => ['A', 'A', 'B', 'A', 'B', 'B'],
|
||||
'2' => ['A', 'A', 'B', 'B', 'A', 'B'],
|
||||
'3' => ['A', 'A', 'B', 'B', 'B', 'A'],
|
||||
'4' => ['A', 'B', 'A', 'A', 'B', 'B'],
|
||||
'5' => ['A', 'B', 'B', 'A', 'A', 'B'],
|
||||
'6' => ['A', 'B', 'B', 'B', 'A', 'A'],
|
||||
'7' => ['A', 'B', 'A', 'B', 'A', 'B'],
|
||||
'8' => ['A', 'B', 'A', 'B', 'B', 'A'],
|
||||
'9' => ['A', 'B', 'B', 'A', 'B', 'A'],
|
||||
];
|
||||
|
||||
$upce_parities = [
|
||||
[
|
||||
'0' => ['B', 'B', 'B', 'A', 'A', 'A'],
|
||||
'1' => ['B', 'B', 'A', 'B', 'A', 'A'],
|
||||
'2' => ['B', 'B', 'A', 'A', 'B', 'A'],
|
||||
'3' => ['B', 'B', 'A', 'A', 'A', 'B'],
|
||||
'4' => ['B', 'A', 'B', 'B', 'A', 'A'],
|
||||
'5' => ['B', 'A', 'A', 'B', 'B', 'A'],
|
||||
'6' => ['B', 'A', 'A', 'A', 'B', 'B'],
|
||||
'7' => ['B', 'A', 'B', 'A', 'B', 'A'],
|
||||
'8' => ['B', 'A', 'B', 'A', 'A', 'B'],
|
||||
'9' => ['B', 'A', 'A', 'B', 'A', 'B'],
|
||||
],
|
||||
[
|
||||
'0' => ['A', 'A', 'A', 'B', 'B', 'B'],
|
||||
'1' => ['A', 'A', 'B', 'A', 'B', 'B'],
|
||||
'2' => ['A', 'A', 'B', 'B', 'A', 'B'],
|
||||
'3' => ['A', 'A', 'B', 'B', 'B', 'A'],
|
||||
'4' => ['A', 'B', 'A', 'A', 'B', 'B'],
|
||||
'5' => ['A', 'B', 'B', 'A', 'A', 'B'],
|
||||
'6' => ['A', 'B', 'B', 'B', 'A', 'A'],
|
||||
'7' => ['A', 'B', 'A', 'B', 'A', 'B'],
|
||||
'8' => ['A', 'B', 'A', 'B', 'B', 'A'],
|
||||
'9' => ['A', 'B', 'B', 'A', 'B', 'A'],
|
||||
],
|
||||
];
|
||||
|
||||
$seq = '101'; // left guard bar
|
||||
if ($this->upce) {
|
||||
$barcode = new Barcode($upce_code);
|
||||
$p = $upce_parities[$code[1]][$checksumDigit];
|
||||
for ($i = 0; $i < 6; ++$i) {
|
||||
$seq .= $codes[$p[$i]][$upce_code[$i]];
|
||||
}
|
||||
$seq .= '010101'; // right guard bar
|
||||
} else {
|
||||
$barcode = new Barcode($code);
|
||||
$half_len = intval(ceil($length / 2));
|
||||
if ($length == 8) {
|
||||
for ($i = 0; $i < $half_len; ++$i) {
|
||||
$seq .= $codes['A'][$code[$i]];
|
||||
}
|
||||
} else {
|
||||
$p = $parities[$code[0]];
|
||||
for ($i = 1; $i < $half_len; ++$i) {
|
||||
$seq .= $codes[$p[$i - 1]][$code[$i]];
|
||||
}
|
||||
}
|
||||
$seq .= '01010'; // center guard bar
|
||||
for ($i = $half_len; $i < $length; ++$i) {
|
||||
if (! isset($codes['C'][$code[$i]])) {
|
||||
throw new InvalidCharacterException('Char ' . $code[$i] . ' not allowed');
|
||||
}
|
||||
$seq .= $codes['C'][$code[$i]];
|
||||
}
|
||||
$seq .= '101'; // right guard bar
|
||||
}
|
||||
|
||||
$clen = strlen($seq);
|
||||
$w = 0;
|
||||
for ($i = 0; $i < $clen; ++$i) {
|
||||
$w += 1;
|
||||
if (($i == ($clen - 1)) OR (($i < ($clen - 1)) AND ($seq[$i] != $seq[($i + 1)]))) {
|
||||
if ($seq[$i] == '1') {
|
||||
$t = true; // bar
|
||||
} else {
|
||||
$t = false; // space
|
||||
}
|
||||
|
||||
$barcode->addBar(new BarcodeBar($w, 1, $t));
|
||||
$w = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return $barcode;
|
||||
}
|
||||
|
||||
protected function calculateChecksumDigit(string $code): int
|
||||
{
|
||||
// calculate check digit
|
||||
$sum_a = 0;
|
||||
for ($i = 1; $i < $this->length - 1; $i += 2) {
|
||||
$sum_a += intval($code[$i]);
|
||||
}
|
||||
if ($this->length > 12) {
|
||||
$sum_a *= 3;
|
||||
}
|
||||
$sum_b = 0;
|
||||
for ($i = 0; $i < $this->length - 1; $i += 2) {
|
||||
$sum_b += intval(($code[$i]));
|
||||
}
|
||||
if ($this->length < 13) {
|
||||
$sum_b *= 3;
|
||||
}
|
||||
$checksumDigit = ($sum_a + $sum_b) % 10;
|
||||
if ($checksumDigit > 0) {
|
||||
$checksumDigit = (10 - $checksumDigit);
|
||||
}
|
||||
|
||||
return $checksumDigit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\BarcodeBar;
|
||||
use Picqer\Barcode\Exceptions\InvalidCharacterException;
|
||||
use Picqer\Barcode\Exceptions\InvalidCheckDigitException;
|
||||
use Picqer\Barcode\Exceptions\InvalidLengthException;
|
||||
|
||||
class TypeITF14 implements TypeInterface
|
||||
{
|
||||
/**
|
||||
* @throws InvalidLengthException
|
||||
* @throws InvalidCharacterException
|
||||
* @throws InvalidCheckDigitException
|
||||
*/
|
||||
public function getBarcode(string $code): Barcode
|
||||
{
|
||||
$chr = [];
|
||||
$chr['0'] = '11221';
|
||||
$chr['1'] = '21112';
|
||||
$chr['2'] = '12112';
|
||||
$chr['3'] = '22111';
|
||||
$chr['4'] = '11212';
|
||||
$chr['5'] = '21211';
|
||||
$chr['6'] = '12211';
|
||||
$chr['7'] = '11122';
|
||||
$chr['8'] = '21121';
|
||||
$chr['9'] = '12121';
|
||||
$chr['A'] = '11';
|
||||
$chr['Z'] = '21';
|
||||
|
||||
if (strlen($code) < 13 || strlen($code) > 14) {
|
||||
throw new InvalidLengthException();
|
||||
}
|
||||
|
||||
if (strlen($code) === 13) {
|
||||
$code .= $this->getChecksum($code);
|
||||
} elseif (substr($code, -1) !== $this->getChecksum(substr($code, 0, -1))) {
|
||||
// If length of given barcode is same as final length, barcode is including checksum
|
||||
// Make sure that checksum is the same as we calculated
|
||||
throw new InvalidCheckDigitException();
|
||||
}
|
||||
|
||||
$barcode = new Barcode($code);
|
||||
|
||||
// Add start and stop codes
|
||||
$code = 'AA' . strtolower($code) . 'ZA';
|
||||
|
||||
// Loop through 2 chars at once
|
||||
for ($charIndex = 0; $charIndex < strlen($code); $charIndex += 2) {
|
||||
if (! isset($chr[$code[$charIndex]]) || ! isset($chr[$code[$charIndex + 1]])) {
|
||||
throw new InvalidCharacterException();
|
||||
}
|
||||
|
||||
$drawBar = true;
|
||||
$pbars = $chr[$code[$charIndex]];
|
||||
$pspaces = $chr[$code[$charIndex + 1]];
|
||||
$pmixed = '';
|
||||
|
||||
while (strlen($pbars) > 0) {
|
||||
$pmixed .= $pbars[0] . $pspaces[0];
|
||||
$pbars = substr($pbars, 1);
|
||||
$pspaces = substr($pspaces, 1);
|
||||
}
|
||||
|
||||
foreach (str_split($pmixed) as $width) {
|
||||
$barcode->addBar(new BarcodeBar(intval($width), 1, $drawBar));
|
||||
$drawBar = ! $drawBar;
|
||||
}
|
||||
}
|
||||
|
||||
return $barcode;
|
||||
}
|
||||
|
||||
private function getChecksum(string $code): string
|
||||
{
|
||||
$total = 0;
|
||||
|
||||
for ($charIndex = 0; $charIndex <= (strlen($code) - 1); $charIndex++) {
|
||||
$integerOfChar = intval($code[$charIndex]);
|
||||
$total += $integerOfChar * ($charIndex % 2 === 0 ? 3 : 1);
|
||||
}
|
||||
|
||||
$checksum = 10 - ($total % 10);
|
||||
if ($checksum === 10) {
|
||||
$checksum = 0;
|
||||
}
|
||||
|
||||
return (string)$checksum;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,571 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\BarcodeBar;
|
||||
use Picqer\Barcode\Exceptions\BarcodeException;
|
||||
|
||||
/*
|
||||
* IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
|
||||
* (requires PHP bcmath extension)
|
||||
* Intelligent Mail barcode is a 65-bar code for use on mail in the United States.
|
||||
* The fields are described as follows:<ul><li>The Barcode Identifier shall be assigned by USPS to encode the
|
||||
* presort identification that is currently printed in human readable form on the optional endorsement line (OEL)
|
||||
* as well as for future USPS use. This shall be two digits, with the second digit in the range of 0–4. The
|
||||
* allowable encoding ranges shall be 00–04, 10–14, 20–24, 30–34, 40–44, 50–54, 60–64, 70–74, 80–84, and
|
||||
* 90–94.</li><li>The Service Type Identifier shall be assigned by USPS for any combination of services requested
|
||||
* on the mailpiece. The allowable encoding range shall be 000http://it2.php.net/manual/en/function.dechex.php–999.
|
||||
* Each 3-digit value shall correspond to a particular mail class with a particular combination of service(s). Each
|
||||
* service program, such as OneCode Confirm and OneCode ACS, shall provide the list of Service Type Identifier
|
||||
* values.</li><li>The Mailer or Customer Identifier shall be assigned by USPS as a unique, 6 or 9 digit number
|
||||
* that identifies a business entity. The allowable encoding range for the 6 digit Mailer ID shall be 000000-
|
||||
* 899999, while the allowable encoding range for the 9 digit Mailer ID shall be 900000000-999999999.</li><li>The
|
||||
* Serial or Sequence Number shall be assigned by the mailer for uniquely identifying and tracking mailpieces. The
|
||||
* allowable encoding range shall be 000000000–999999999 when used with a 6 digit Mailer ID and 000000-999999 when
|
||||
* used with a 9 digit Mailer ID. e. The Delivery Point ZIP Code shall be assigned by the mailer for routing the
|
||||
* mailpiece. This shall replace POSTNET for routing the mailpiece to its final delivery point. The length may be
|
||||
* 0, 5, 9, or 11 digits. The allowable encoding ranges shall be no ZIP Code, 00000–99999, 000000000–999999999,
|
||||
* and 00000000000–99999999999.</li></ul>
|
||||
*
|
||||
* code to print, separate the ZIP (routing code) from the rest using a minus char '-'
|
||||
* (BarcodeID_ServiceTypeID_MailerID_SerialNumber-RoutingCode)
|
||||
*/
|
||||
|
||||
class TypeIntelligentMailBarcode implements TypeInterface
|
||||
{
|
||||
public function getBarcode(string $code): Barcode
|
||||
{
|
||||
$asc_chr = [
|
||||
4,
|
||||
0,
|
||||
2,
|
||||
6,
|
||||
3,
|
||||
5,
|
||||
1,
|
||||
9,
|
||||
8,
|
||||
7,
|
||||
1,
|
||||
2,
|
||||
0,
|
||||
6,
|
||||
4,
|
||||
8,
|
||||
2,
|
||||
9,
|
||||
5,
|
||||
3,
|
||||
0,
|
||||
1,
|
||||
3,
|
||||
7,
|
||||
4,
|
||||
6,
|
||||
8,
|
||||
9,
|
||||
2,
|
||||
0,
|
||||
5,
|
||||
1,
|
||||
9,
|
||||
4,
|
||||
3,
|
||||
8,
|
||||
6,
|
||||
7,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
3,
|
||||
9,
|
||||
5,
|
||||
7,
|
||||
8,
|
||||
3,
|
||||
0,
|
||||
2,
|
||||
1,
|
||||
4,
|
||||
0,
|
||||
9,
|
||||
1,
|
||||
7,
|
||||
0,
|
||||
2,
|
||||
4,
|
||||
6,
|
||||
3,
|
||||
7,
|
||||
1,
|
||||
9,
|
||||
5,
|
||||
8
|
||||
];
|
||||
$dsc_chr = [
|
||||
7,
|
||||
1,
|
||||
9,
|
||||
5,
|
||||
8,
|
||||
0,
|
||||
2,
|
||||
4,
|
||||
6,
|
||||
3,
|
||||
5,
|
||||
8,
|
||||
9,
|
||||
7,
|
||||
3,
|
||||
0,
|
||||
6,
|
||||
1,
|
||||
7,
|
||||
4,
|
||||
6,
|
||||
8,
|
||||
9,
|
||||
2,
|
||||
5,
|
||||
1,
|
||||
7,
|
||||
5,
|
||||
4,
|
||||
3,
|
||||
8,
|
||||
7,
|
||||
6,
|
||||
0,
|
||||
2,
|
||||
5,
|
||||
4,
|
||||
9,
|
||||
3,
|
||||
0,
|
||||
1,
|
||||
6,
|
||||
8,
|
||||
2,
|
||||
0,
|
||||
4,
|
||||
5,
|
||||
9,
|
||||
6,
|
||||
7,
|
||||
5,
|
||||
2,
|
||||
6,
|
||||
3,
|
||||
8,
|
||||
5,
|
||||
1,
|
||||
9,
|
||||
8,
|
||||
7,
|
||||
4,
|
||||
0,
|
||||
2,
|
||||
6,
|
||||
3
|
||||
];
|
||||
$asc_pos = [
|
||||
3,
|
||||
0,
|
||||
8,
|
||||
11,
|
||||
1,
|
||||
12,
|
||||
8,
|
||||
11,
|
||||
10,
|
||||
6,
|
||||
4,
|
||||
12,
|
||||
2,
|
||||
7,
|
||||
9,
|
||||
6,
|
||||
7,
|
||||
9,
|
||||
2,
|
||||
8,
|
||||
4,
|
||||
0,
|
||||
12,
|
||||
7,
|
||||
10,
|
||||
9,
|
||||
0,
|
||||
7,
|
||||
10,
|
||||
5,
|
||||
7,
|
||||
9,
|
||||
6,
|
||||
8,
|
||||
2,
|
||||
12,
|
||||
1,
|
||||
4,
|
||||
2,
|
||||
0,
|
||||
1,
|
||||
5,
|
||||
4,
|
||||
6,
|
||||
12,
|
||||
1,
|
||||
0,
|
||||
9,
|
||||
4,
|
||||
7,
|
||||
5,
|
||||
10,
|
||||
2,
|
||||
6,
|
||||
9,
|
||||
11,
|
||||
2,
|
||||
12,
|
||||
6,
|
||||
7,
|
||||
5,
|
||||
11,
|
||||
0,
|
||||
3,
|
||||
2
|
||||
];
|
||||
$dsc_pos = [
|
||||
2,
|
||||
10,
|
||||
12,
|
||||
5,
|
||||
9,
|
||||
1,
|
||||
5,
|
||||
4,
|
||||
3,
|
||||
9,
|
||||
11,
|
||||
5,
|
||||
10,
|
||||
1,
|
||||
6,
|
||||
3,
|
||||
4,
|
||||
1,
|
||||
10,
|
||||
0,
|
||||
2,
|
||||
11,
|
||||
8,
|
||||
6,
|
||||
1,
|
||||
12,
|
||||
3,
|
||||
8,
|
||||
6,
|
||||
4,
|
||||
4,
|
||||
11,
|
||||
0,
|
||||
6,
|
||||
1,
|
||||
9,
|
||||
11,
|
||||
5,
|
||||
3,
|
||||
7,
|
||||
3,
|
||||
10,
|
||||
7,
|
||||
11,
|
||||
8,
|
||||
2,
|
||||
10,
|
||||
3,
|
||||
5,
|
||||
8,
|
||||
0,
|
||||
3,
|
||||
12,
|
||||
11,
|
||||
8,
|
||||
4,
|
||||
5,
|
||||
1,
|
||||
3,
|
||||
0,
|
||||
7,
|
||||
12,
|
||||
9,
|
||||
8,
|
||||
10
|
||||
];
|
||||
$code_arr = explode('-', $code);
|
||||
$tracking_number = $code_arr[0];
|
||||
if (isset($code_arr[1])) {
|
||||
$routing_code = $code_arr[1];
|
||||
} else {
|
||||
$routing_code = '';
|
||||
}
|
||||
// Conversion of Routing Code
|
||||
switch (strlen($routing_code)) {
|
||||
case 0:
|
||||
$binary_code = 0;
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$binary_code = bcadd($routing_code, '1');
|
||||
break;
|
||||
|
||||
case 9:
|
||||
$binary_code = bcadd($routing_code, '100001');
|
||||
break;
|
||||
|
||||
case 11:
|
||||
$binary_code = bcadd($routing_code, '1000100001');
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new BarcodeException('Routing code unknown');
|
||||
}
|
||||
|
||||
$binary_code = bcmul($binary_code, strval(10));
|
||||
$binary_code = bcadd($binary_code, $tracking_number[0]);
|
||||
$binary_code = bcmul($binary_code, strval(5));
|
||||
$binary_code = bcadd($binary_code, $tracking_number[1]);
|
||||
$binary_code .= substr($tracking_number, 2, 18);
|
||||
|
||||
// convert to hexadecimal
|
||||
$binary_code = $this->dec_to_hex($binary_code);
|
||||
|
||||
// pad to get 13 bytes
|
||||
$binary_code = str_pad($binary_code, 26, '0', STR_PAD_LEFT);
|
||||
|
||||
// convert string to array of bytes
|
||||
$binary_code_arr = chunk_split($binary_code, 2, "\r");
|
||||
$binary_code_arr = substr($binary_code_arr, 0, -1);
|
||||
$binary_code_arr = explode("\r", $binary_code_arr);
|
||||
|
||||
// calculate frame check sequence
|
||||
$fcs = $this->imb_crc11fcs($binary_code_arr);
|
||||
|
||||
// exclude first 2 bits from first byte
|
||||
$first_byte = sprintf('%2s', dechex((hexdec($binary_code_arr[0]) << 2) >> 2));
|
||||
$binary_code_102bit = $first_byte . substr($binary_code, 2);
|
||||
|
||||
// convert binary data to codewords
|
||||
$codewords = [];
|
||||
$data = $this->hex_to_dec($binary_code_102bit);
|
||||
$codewords[0] = bcmod($data, strval(636)) * 2;
|
||||
$data = bcdiv($data, strval(636));
|
||||
for ($i = 1; $i < 9; ++$i) {
|
||||
$codewords[$i] = bcmod($data, strval(1365));
|
||||
$data = bcdiv($data, strval(1365));
|
||||
}
|
||||
$codewords[9] = $data;
|
||||
if (($fcs >> 10) == 1) {
|
||||
$codewords[9] += 659;
|
||||
}
|
||||
|
||||
// generate lookup tables
|
||||
$table2of13 = $this->imb_tables(2, 78);
|
||||
$table5of13 = $this->imb_tables(5, 1287);
|
||||
|
||||
// convert codewords to characters
|
||||
$characters = [];
|
||||
$bitmask = 512;
|
||||
foreach ($codewords as $val) {
|
||||
if ($val <= 1286) {
|
||||
$chrcode = (int)$table5of13[$val];
|
||||
} else {
|
||||
$chrcode = (int)$table2of13[($val - 1287)];
|
||||
}
|
||||
if (($fcs & $bitmask) > 0) {
|
||||
// bitwise invert
|
||||
$chrcode = ((~$chrcode) & 8191);
|
||||
}
|
||||
$characters[] = $chrcode;
|
||||
$bitmask /= 2;
|
||||
}
|
||||
$characters = array_reverse($characters);
|
||||
|
||||
// build bars
|
||||
$barcode = new Barcode($code);
|
||||
for ($i = 0; $i < 65; ++$i) {
|
||||
$asc = (($characters[$asc_chr[$i]] & pow(2, $asc_pos[$i])) > 0);
|
||||
$dsc = (($characters[$dsc_chr[$i]] & pow(2, $dsc_pos[$i])) > 0);
|
||||
if ($asc AND $dsc) {
|
||||
// full bar (F)
|
||||
$p = 0;
|
||||
$h = 3;
|
||||
} elseif ($asc) {
|
||||
// ascender (A)
|
||||
$p = 0;
|
||||
$h = 2;
|
||||
} elseif ($dsc) {
|
||||
// descender (D)
|
||||
$p = 1;
|
||||
$h = 2;
|
||||
} else {
|
||||
// tracker (T)
|
||||
$p = 1;
|
||||
$h = 1;
|
||||
}
|
||||
$barcode->addBar(new BarcodeBar(1, $h, true, $p));
|
||||
if ($i < 64) {
|
||||
$barcode->addBar(new BarcodeBar(1, 2, false, 0));
|
||||
}
|
||||
}
|
||||
|
||||
return $barcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert large integer number to hexadecimal representation.
|
||||
* (requires PHP bcmath extension)
|
||||
*
|
||||
* @param $number (string) number to convert specified as a string
|
||||
* @return string hexadecimal representation
|
||||
*/
|
||||
protected function dec_to_hex($number)
|
||||
{
|
||||
if ($number == 0) {
|
||||
return '00';
|
||||
}
|
||||
|
||||
$hex = [];
|
||||
|
||||
while ($number > 0) {
|
||||
$hex[] = strtoupper(dechex(intval(bcmod(strval($number), '16'))));
|
||||
$number = bcdiv($number, '16', 0);
|
||||
}
|
||||
$hex = array_reverse($hex);
|
||||
|
||||
return implode($hex);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Intelligent Mail Barcode calculation of Frame Check Sequence
|
||||
*
|
||||
* @param $code_arr (string) array of hexadecimal values (13 bytes holding 102 bits right justified).
|
||||
* @return int 11 bit Frame Check Sequence as integer (decimal base)
|
||||
* @protected
|
||||
*/
|
||||
protected function imb_crc11fcs($code_arr)
|
||||
{
|
||||
$genpoly = 0x0F35; // generator polynomial
|
||||
$fcs = 0x07FF; // Frame Check Sequence
|
||||
// do most significant byte skipping the 2 most significant bits
|
||||
$data = hexdec($code_arr[0]) << 5;
|
||||
for ($bit = 2; $bit < 8; ++$bit) {
|
||||
if (($fcs ^ $data) & 0x400) {
|
||||
$fcs = ($fcs << 1) ^ $genpoly;
|
||||
} else {
|
||||
$fcs = ($fcs << 1);
|
||||
}
|
||||
$fcs &= 0x7FF;
|
||||
$data <<= 1;
|
||||
}
|
||||
// do rest of bytes
|
||||
for ($byte = 1; $byte < 13; ++$byte) {
|
||||
$data = hexdec($code_arr[$byte]) << 3;
|
||||
for ($bit = 0; $bit < 8; ++$bit) {
|
||||
if (($fcs ^ $data) & 0x400) {
|
||||
$fcs = ($fcs << 1) ^ $genpoly;
|
||||
} else {
|
||||
$fcs = ($fcs << 1);
|
||||
}
|
||||
$fcs &= 0x7FF;
|
||||
$data <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
return $fcs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert large hexadecimal number to decimal representation (string).
|
||||
* (requires PHP bcmath extension)
|
||||
*
|
||||
* @param $hex (string) hexadecimal number to convert specified as a string
|
||||
* @return string hexadecimal representation
|
||||
*/
|
||||
protected function hex_to_dec($hex)
|
||||
{
|
||||
$dec = 0;
|
||||
$bitval = 1;
|
||||
$len = strlen($hex);
|
||||
for ($pos = ($len - 1); $pos >= 0; --$pos) {
|
||||
$dec = bcadd($dec, bcmul(strval(hexdec($hex[$pos])), strval($bitval)));
|
||||
$bitval = bcmul($bitval, '16');
|
||||
}
|
||||
|
||||
return $dec;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* generate Nof13 tables used for Intelligent Mail Barcode
|
||||
*
|
||||
* @param $n (int) is the type of table: 2 for 2of13 table, 5 for 5of13table
|
||||
* @param $size (int) size of table (78 for n=2 and 1287 for n=5)
|
||||
* @return array requested table
|
||||
* @protected
|
||||
*/
|
||||
protected function imb_tables(int $n, int $size): array
|
||||
{
|
||||
$table = [];
|
||||
$lli = 0; // LUT lower index
|
||||
$lui = $size - 1; // LUT upper index
|
||||
for ($count = 0; $count < 8192; ++$count) {
|
||||
$bit_count = 0;
|
||||
for ($bit_index = 0; $bit_index < 13; ++$bit_index) {
|
||||
$bit_count += intval(($count & (1 << $bit_index)) != 0);
|
||||
}
|
||||
// if we don't have the right number of bits on, go on to the next value
|
||||
if ($bit_count == $n) {
|
||||
$reverse = ($this->imb_reverse_us($count) >> 3);
|
||||
// if the reverse is less than count, we have already visited this pair before
|
||||
if ($reverse >= $count) {
|
||||
// If count is symmetric, place it at the first free slot from the end of the list.
|
||||
// Otherwise, place it at the first free slot from the beginning of the list AND place $reverse ath the next free slot from the beginning of the list
|
||||
if ($reverse == $count) {
|
||||
$table[$lui] = $count;
|
||||
--$lui;
|
||||
} else {
|
||||
$table[$lli] = $count;
|
||||
++$lli;
|
||||
$table[$lli] = $reverse;
|
||||
++$lli;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse unsigned short value
|
||||
*
|
||||
* @param $num (int) value to reversr
|
||||
* @return int reversed value
|
||||
* @protected
|
||||
*/
|
||||
protected function imb_reverse_us($num)
|
||||
{
|
||||
$rev = 0;
|
||||
for ($i = 0; $i < 16; ++$i) {
|
||||
$rev <<= 1;
|
||||
$rev |= ($num & 1);
|
||||
$num >>= 1;
|
||||
}
|
||||
|
||||
return $rev;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
|
||||
interface TypeInterface
|
||||
{
|
||||
public function getBarcode(string $code): Barcode;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
/*
|
||||
* Interleaved 2 of 5 barcodes.
|
||||
* Compact numeric code, widely used in industry, air cargo
|
||||
* Contains digits (0 to 9) and encodes the data in the width of both bars and spaces.
|
||||
*/
|
||||
|
||||
class TypeInterleaved25 extends TypeInterleaved25Checksum
|
||||
{
|
||||
protected function getChecksum(string $code): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\BarcodeBar;
|
||||
use Picqer\Barcode\Exceptions\InvalidCharacterException;
|
||||
|
||||
/*
|
||||
* Interleaved 2 of 5 barcodes.
|
||||
* Compact numeric code, widely used in industry, air cargo
|
||||
* Contains digits (0 to 9) and encodes the data in the width of both bars and spaces.
|
||||
*/
|
||||
|
||||
class TypeInterleaved25Checksum implements TypeInterface
|
||||
{
|
||||
public function getBarcode(string $code): Barcode
|
||||
{
|
||||
$chr = [];
|
||||
$chr['0'] = '11221';
|
||||
$chr['1'] = '21112';
|
||||
$chr['2'] = '12112';
|
||||
$chr['3'] = '22111';
|
||||
$chr['4'] = '11212';
|
||||
$chr['5'] = '21211';
|
||||
$chr['6'] = '12211';
|
||||
$chr['7'] = '11122';
|
||||
$chr['8'] = '21121';
|
||||
$chr['9'] = '12121';
|
||||
$chr['A'] = '11';
|
||||
$chr['Z'] = '21';
|
||||
|
||||
// add checksum
|
||||
$code .= $this->getChecksum($code);
|
||||
|
||||
if ((strlen($code) % 2) != 0) {
|
||||
// add leading zero if code-length is odd
|
||||
$code = '0' . $code;
|
||||
}
|
||||
|
||||
// add start and stop codes
|
||||
$code = 'AA' . strtolower($code) . 'ZA';
|
||||
|
||||
$barcode = new Barcode($code);
|
||||
for ($i = 0; $i < strlen($code); $i = ($i + 2)) {
|
||||
$char_bar = $code[$i];
|
||||
$char_space = $code[$i + 1];
|
||||
if (! isset($chr[$char_bar]) || ! isset($chr[$char_space])) {
|
||||
throw new InvalidCharacterException();
|
||||
}
|
||||
|
||||
// create a bar-space sequence
|
||||
$seq = '';
|
||||
$chrlen = strlen($chr[$char_bar]);
|
||||
for ($s = 0; $s < $chrlen; $s++) {
|
||||
$seq .= $chr[$char_bar][$s] . $chr[$char_space][$s];
|
||||
}
|
||||
|
||||
for ($j = 0; $j < strlen($seq); ++$j) {
|
||||
if (($j % 2) == 0) {
|
||||
$t = true; // bar
|
||||
} else {
|
||||
$t = false; // space
|
||||
}
|
||||
$w = intval($seq[$j]);
|
||||
$barcode->addBar(new BarcodeBar($w, 1, $t));
|
||||
}
|
||||
}
|
||||
|
||||
return $barcode;
|
||||
}
|
||||
|
||||
protected function getChecksum(string $code): string
|
||||
{
|
||||
$len = strlen($code);
|
||||
$sum = 0;
|
||||
for ($i = 0; $i < $len; $i += 2) {
|
||||
$sum += intval($code[$i]);
|
||||
}
|
||||
$sum *= 3;
|
||||
for ($i = 1; $i < $len; $i += 2) {
|
||||
$sum += intval($code[$i]);
|
||||
}
|
||||
$r = $sum % 10;
|
||||
if ($r > 0) {
|
||||
$r = (10 - $r);
|
||||
}
|
||||
|
||||
return (string)$r;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
/*
|
||||
* RMS4CC - CBC - KIX
|
||||
* RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code) - KIX (Klant index - Customer index)
|
||||
* RM4SCC is the name of the barcode symbology used by the Royal Mail for its Cleanmail service.
|
||||
* @param $kix (boolean) if true prints the KIX variation (doesn't use the start and end symbols, and the checksum)
|
||||
* - in this case the house number must be sufficed with an X and placed at the end of the code.
|
||||
*/
|
||||
|
||||
class TypeKix extends TypeRms4cc
|
||||
{
|
||||
protected bool $kix = true;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
/*
|
||||
* MSI.
|
||||
* Variation of Plessey code, with similar applications
|
||||
* Contains digits (0 to 9) and encodes the data only in the width of bars.
|
||||
*
|
||||
* @param $code (string) code to represent.
|
||||
* @param $checksum (boolean) if true add a checksum to the code (modulo 11)
|
||||
*/
|
||||
|
||||
class TypeMsi extends TypeMsiChecksum
|
||||
{
|
||||
protected bool $checksum = false;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\Exceptions\InvalidCharacterException;
|
||||
use Picqer\Barcode\Helpers\BinarySequenceConverter;
|
||||
|
||||
/*
|
||||
* MSI.
|
||||
* Variation of Plessey code, with similar applications
|
||||
* Contains digits (0 to 9) and encodes the data only in the width of bars.
|
||||
*
|
||||
* @param $code (string) code to represent.
|
||||
* @param $checksum (boolean) if true add a checksum to the code (modulo 11)
|
||||
*/
|
||||
|
||||
class TypeMsiChecksum implements TypeInterface
|
||||
{
|
||||
protected bool $checksum = true;
|
||||
|
||||
public function getBarcode(string $code): Barcode
|
||||
{
|
||||
$chr['0'] = '100100100100';
|
||||
$chr['1'] = '100100100110';
|
||||
$chr['2'] = '100100110100';
|
||||
$chr['3'] = '100100110110';
|
||||
$chr['4'] = '100110100100';
|
||||
$chr['5'] = '100110100110';
|
||||
$chr['6'] = '100110110100';
|
||||
$chr['7'] = '100110110110';
|
||||
$chr['8'] = '110100100100';
|
||||
$chr['9'] = '110100100110';
|
||||
$chr['A'] = '110100110100';
|
||||
$chr['B'] = '110100110110';
|
||||
$chr['C'] = '110110100100';
|
||||
$chr['D'] = '110110100110';
|
||||
$chr['E'] = '110110110100';
|
||||
$chr['F'] = '110110110110';
|
||||
if ($this->checksum) {
|
||||
// add checksum
|
||||
$clen = strlen($code);
|
||||
$p = 2;
|
||||
$check = 0;
|
||||
for ($i = ($clen - 1); $i >= 0; --$i) {
|
||||
$check += (hexdec($code[$i]) * $p);
|
||||
++$p;
|
||||
if ($p > 7) {
|
||||
$p = 2;
|
||||
}
|
||||
}
|
||||
$check %= 11;
|
||||
if ($check > 0) {
|
||||
$check = 11 - $check;
|
||||
}
|
||||
$code .= $check;
|
||||
}
|
||||
$seq = '110'; // left guard
|
||||
$clen = strlen($code);
|
||||
for ($i = 0; $i < $clen; ++$i) {
|
||||
$digit = $code[$i];
|
||||
if (! isset($chr[$digit])) {
|
||||
throw new InvalidCharacterException('Char ' . $digit . ' is unsupported');
|
||||
}
|
||||
$seq .= $chr[$digit];
|
||||
}
|
||||
$seq .= '1001'; // right guard
|
||||
|
||||
return BinarySequenceConverter::convert($code, $seq);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\Helpers\BinarySequenceConverter;
|
||||
|
||||
/*
|
||||
* Pharmacode
|
||||
* Contains digits (0 to 9)
|
||||
*/
|
||||
|
||||
class TypePharmacode implements TypeInterface
|
||||
{
|
||||
public function getBarcode(string $code): Barcode
|
||||
{
|
||||
$originalCode = $code;
|
||||
|
||||
$code = intval($code);
|
||||
|
||||
$seq = '';
|
||||
while ($code > 0) {
|
||||
if (($code % 2) == 0) {
|
||||
$seq .= '11100';
|
||||
$code -= 2;
|
||||
} else {
|
||||
$seq .= '100';
|
||||
$code -= 1;
|
||||
}
|
||||
$code /= 2;
|
||||
}
|
||||
|
||||
$seq = substr($seq, 0, -2);
|
||||
$seq = strrev($seq);
|
||||
|
||||
return BinarySequenceConverter::convert($originalCode, $seq);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
/*
|
||||
* Pharmacode two-track
|
||||
* Contains digits (0 to 9)
|
||||
*/
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\BarcodeBar;
|
||||
use Picqer\Barcode\Exceptions\InvalidCharacterException;
|
||||
use Picqer\Barcode\Exceptions\InvalidLengthException;
|
||||
|
||||
class TypePharmacodeTwoCode implements TypeInterface
|
||||
{
|
||||
public function getBarcode(string $code): Barcode
|
||||
{
|
||||
$originalCode = $code;
|
||||
|
||||
$code = intval($code);
|
||||
|
||||
if ($code < 1) {
|
||||
throw new InvalidLengthException('Pharmacode 2 needs a number of 1 or larger');
|
||||
}
|
||||
|
||||
$seq = '';
|
||||
|
||||
do {
|
||||
switch ($code % 3) {
|
||||
case 0:
|
||||
$seq .= '3';
|
||||
$code = ($code - 3) / 3;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$seq .= '1';
|
||||
$code = ($code - 1) / 3;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$seq .= '2';
|
||||
$code = ($code - 2) / 3;
|
||||
break;
|
||||
}
|
||||
} while ($code != 0);
|
||||
|
||||
$seq = strrev($seq);
|
||||
|
||||
$barcode = new Barcode($originalCode);
|
||||
|
||||
for ($i = 0; $i < strlen($seq); ++$i) {
|
||||
switch ($seq[$i]) {
|
||||
case '1':
|
||||
$p = 1;
|
||||
$h = 1;
|
||||
break;
|
||||
|
||||
case '2':
|
||||
$p = 0;
|
||||
$h = 1;
|
||||
break;
|
||||
|
||||
case '3':
|
||||
$p = 0;
|
||||
$h = 2;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new InvalidCharacterException('Could not find bar for char.');
|
||||
}
|
||||
|
||||
$barcode->addBar(new BarcodeBar(1, $h, true, $p));
|
||||
if ($i < (strlen($seq) - 1)) {
|
||||
$barcode->addBar(new BarcodeBar(1, 2, false, 0));
|
||||
}
|
||||
}
|
||||
|
||||
return $barcode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
/*
|
||||
* PLANET barcodes.
|
||||
* Used by U.S. Postal Service for automated mail sorting
|
||||
*
|
||||
* @param $code (string) zip code to represent. Must be a string containing a zip code of the form DDDDD or
|
||||
* DDDDD-DDDD.
|
||||
* @param $planet (boolean) if true print the PLANET barcode, otherwise print POSTNET
|
||||
*/
|
||||
|
||||
class TypePlanet extends TypePostnet
|
||||
{
|
||||
protected array $barlen = [
|
||||
0 => [1, 1, 2, 2, 2],
|
||||
1 => [2, 2, 2, 1, 1],
|
||||
2 => [2, 2, 1, 2, 1],
|
||||
3 => [2, 2, 1, 1, 2],
|
||||
4 => [2, 1, 2, 2, 1],
|
||||
5 => [2, 1, 2, 1, 2],
|
||||
6 => [2, 1, 1, 2, 2],
|
||||
7 => [1, 2, 2, 2, 1],
|
||||
8 => [1, 2, 2, 1, 2],
|
||||
9 => [1, 2, 1, 2, 2]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
/*
|
||||
* POSTNET and PLANET barcodes.
|
||||
* Used by U.S. Postal Service for automated mail sorting
|
||||
*
|
||||
* @param $code (string) zip code to represent. Must be a string containing a zip code of the form DDDDD or
|
||||
* DDDDD-DDDD.
|
||||
* @param $planet (boolean) if true print the PLANET barcode, otherwise print POSTNET
|
||||
*/
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\BarcodeBar;
|
||||
|
||||
class TypePostnet implements TypeInterface
|
||||
{
|
||||
protected array $barlen = [
|
||||
0 => [2, 2, 1, 1, 1],
|
||||
1 => [1, 1, 1, 2, 2],
|
||||
2 => [1, 1, 2, 1, 2],
|
||||
3 => [1, 1, 2, 2, 1],
|
||||
4 => [1, 2, 1, 1, 2],
|
||||
5 => [1, 2, 1, 2, 1],
|
||||
6 => [1, 2, 2, 1, 1],
|
||||
7 => [2, 1, 1, 1, 2],
|
||||
8 => [2, 1, 1, 2, 1],
|
||||
9 => [2, 1, 2, 1, 1]
|
||||
];
|
||||
|
||||
public function getBarcode(string $code): Barcode
|
||||
{
|
||||
$code = str_replace(['-', ' '], '', $code);
|
||||
$len = strlen($code);
|
||||
|
||||
$barcode = new Barcode($code);
|
||||
|
||||
// calculate checksum
|
||||
$sum = 0;
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$sum += intval($code[$i]);
|
||||
}
|
||||
$chkd = ($sum % 10);
|
||||
if ($chkd > 0) {
|
||||
$chkd = (10 - $chkd);
|
||||
}
|
||||
$code .= $chkd;
|
||||
$len = strlen($code);
|
||||
|
||||
// start bar
|
||||
$barcode->addBar(new BarcodeBar(1, 2, true));
|
||||
$barcode->addBar(new BarcodeBar(1, 2, false));
|
||||
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
for ($j = 0; $j < 5; ++$j) {
|
||||
$h = $this->barlen[$code[$i]][$j];
|
||||
$p = (int)floor(1 / $h);
|
||||
$barcode->addBar(new BarcodeBar(1, (int)$h, true, $p));
|
||||
$barcode->addBar(new BarcodeBar(1, 2, false));
|
||||
}
|
||||
}
|
||||
|
||||
// end bar
|
||||
$barcode->addBar(new BarcodeBar(1, 2, true));
|
||||
|
||||
return $barcode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
/*
|
||||
* RMS4CC - CBC - KIX
|
||||
* RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code) - KIX (Klant index - Customer index)
|
||||
* RM4SCC is the name of the barcode symbology used by the Royal Mail for its Cleanmail service.
|
||||
* @param $kix (boolean) if true prints the KIX variation (doesn't use the start and end symbols, and the checksum)
|
||||
* - in this case the house number must be sufficed with an X and placed at the end of the code.
|
||||
*/
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\BarcodeBar;
|
||||
|
||||
class TypeRms4cc implements TypeInterface
|
||||
{
|
||||
protected bool $kix = false;
|
||||
|
||||
public function getBarcode(string $code): Barcode
|
||||
{
|
||||
// bar mode
|
||||
// 1 = pos 1, length 2
|
||||
// 2 = pos 1, length 3
|
||||
// 3 = pos 2, length 1
|
||||
// 4 = pos 2, length 2
|
||||
$barmode = [
|
||||
'0' => [3, 3, 2, 2],
|
||||
'1' => [3, 4, 1, 2],
|
||||
'2' => [3, 4, 2, 1],
|
||||
'3' => [4, 3, 1, 2],
|
||||
'4' => [4, 3, 2, 1],
|
||||
'5' => [4, 4, 1, 1],
|
||||
'6' => [3, 1, 4, 2],
|
||||
'7' => [3, 2, 3, 2],
|
||||
'8' => [3, 2, 4, 1],
|
||||
'9' => [4, 1, 3, 2],
|
||||
'A' => [4, 1, 4, 1],
|
||||
'B' => [4, 2, 3, 1],
|
||||
'C' => [3, 1, 2, 4],
|
||||
'D' => [3, 2, 1, 4],
|
||||
'E' => [3, 2, 2, 3],
|
||||
'F' => [4, 1, 1, 4],
|
||||
'G' => [4, 1, 2, 3],
|
||||
'H' => [4, 2, 1, 3],
|
||||
'I' => [1, 3, 4, 2],
|
||||
'J' => [1, 4, 3, 2],
|
||||
'K' => [1, 4, 4, 1],
|
||||
'L' => [2, 3, 3, 2],
|
||||
'M' => [2, 3, 4, 1],
|
||||
'N' => [2, 4, 3, 1],
|
||||
'O' => [1, 3, 2, 4],
|
||||
'P' => [1, 4, 1, 4],
|
||||
'Q' => [1, 4, 2, 3],
|
||||
'R' => [2, 3, 1, 4],
|
||||
'S' => [2, 3, 2, 3],
|
||||
'T' => [2, 4, 1, 3],
|
||||
'U' => [1, 1, 4, 4],
|
||||
'V' => [1, 2, 3, 4],
|
||||
'W' => [1, 2, 4, 3],
|
||||
'X' => [2, 1, 3, 4],
|
||||
'Y' => [2, 1, 4, 3],
|
||||
'Z' => [2, 2, 3, 3]
|
||||
];
|
||||
|
||||
$code = strtoupper($code);
|
||||
$len = strlen($code);
|
||||
|
||||
$barcode = new Barcode($code);
|
||||
|
||||
if (! $this->kix) {
|
||||
// table for checksum calculation (row,col)
|
||||
$checktable = [
|
||||
'0' => [1, 1],
|
||||
'1' => [1, 2],
|
||||
'2' => [1, 3],
|
||||
'3' => [1, 4],
|
||||
'4' => [1, 5],
|
||||
'5' => [1, 0],
|
||||
'6' => [2, 1],
|
||||
'7' => [2, 2],
|
||||
'8' => [2, 3],
|
||||
'9' => [2, 4],
|
||||
'A' => [2, 5],
|
||||
'B' => [2, 0],
|
||||
'C' => [3, 1],
|
||||
'D' => [3, 2],
|
||||
'E' => [3, 3],
|
||||
'F' => [3, 4],
|
||||
'G' => [3, 5],
|
||||
'H' => [3, 0],
|
||||
'I' => [4, 1],
|
||||
'J' => [4, 2],
|
||||
'K' => [4, 3],
|
||||
'L' => [4, 4],
|
||||
'M' => [4, 5],
|
||||
'N' => [4, 0],
|
||||
'O' => [5, 1],
|
||||
'P' => [5, 2],
|
||||
'Q' => [5, 3],
|
||||
'R' => [5, 4],
|
||||
'S' => [5, 5],
|
||||
'T' => [5, 0],
|
||||
'U' => [0, 1],
|
||||
'V' => [0, 2],
|
||||
'W' => [0, 3],
|
||||
'X' => [0, 4],
|
||||
'Y' => [0, 5],
|
||||
'Z' => [0, 0]
|
||||
];
|
||||
|
||||
$row = 0;
|
||||
$col = 0;
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$row += $checktable[$code[$i]][0];
|
||||
$col += $checktable[$code[$i]][1];
|
||||
}
|
||||
$row %= 6;
|
||||
$col %= 6;
|
||||
$chk = array_keys($checktable, [$row, $col]);
|
||||
$code .= $chk[0];
|
||||
++$len;
|
||||
|
||||
// start bar
|
||||
$barcode->addBar(new BarcodeBar(1, 2, true));
|
||||
$barcode->addBar(new BarcodeBar(1, 2, false));
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
for ($j = 0; $j < 4; ++$j) {
|
||||
switch ($barmode[$code[$i]][$j]) {
|
||||
case 1:
|
||||
$p = 0;
|
||||
$h = 2;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$p = 0;
|
||||
$h = 3;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$p = 1;
|
||||
$h = 1;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$p = 1;
|
||||
$h = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
$barcode->addBar(new BarcodeBar(1, $h, true, $p));
|
||||
$barcode->addBar(new BarcodeBar(1, 2, false));
|
||||
}
|
||||
}
|
||||
|
||||
if (! $this->kix) {
|
||||
// stop bar
|
||||
$barcode->addBar(new BarcodeBar(1, 3, true));
|
||||
}
|
||||
|
||||
return $barcode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\Exceptions\InvalidCharacterException;
|
||||
use Picqer\Barcode\Helpers\BinarySequenceConverter;
|
||||
|
||||
/*
|
||||
* Standard 2 of 5 barcodes.
|
||||
* Used in airline ticket marking, photofinishing
|
||||
* Contains digits (0 to 9) and encodes the data only in the width of bars.
|
||||
*/
|
||||
|
||||
class TypeStandard2of5 implements TypeInterface
|
||||
{
|
||||
protected bool $checksum = false;
|
||||
|
||||
public function getBarcode(string $code): Barcode
|
||||
{
|
||||
$chr['0'] = '10101110111010';
|
||||
$chr['1'] = '11101010101110';
|
||||
$chr['2'] = '10111010101110';
|
||||
$chr['3'] = '11101110101010';
|
||||
$chr['4'] = '10101110101110';
|
||||
$chr['5'] = '11101011101010';
|
||||
$chr['6'] = '10111011101010';
|
||||
$chr['7'] = '10101011101110';
|
||||
$chr['8'] = '11101010111010';
|
||||
$chr['9'] = '10111010111010';
|
||||
if ($this->checksum) {
|
||||
// add checksum
|
||||
$code .= $this->checksum_s25($code);
|
||||
}
|
||||
$seq = '11011010';
|
||||
|
||||
for ($i = 0; $i < strlen($code); ++$i) {
|
||||
$digit = $code[$i];
|
||||
if (! isset($chr[$digit])) {
|
||||
throw new InvalidCharacterException('Char ' . $digit . ' is unsupported');
|
||||
}
|
||||
$seq .= $chr[$digit];
|
||||
}
|
||||
$seq .= '1101011';
|
||||
|
||||
return BinarySequenceConverter::convert($code, $seq);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checksum for standard 2 of 5 barcodes.
|
||||
*
|
||||
* @param $code (string) code to process.
|
||||
* @return string checksum.
|
||||
* @protected
|
||||
*/
|
||||
protected function checksum_s25(string $code): string
|
||||
{
|
||||
$len = strlen($code);
|
||||
$sum = 0;
|
||||
for ($i = 0; $i < $len; $i += 2) {
|
||||
$sum += intval($code[$i]);
|
||||
}
|
||||
$sum *= 3;
|
||||
for ($i = 1; $i < $len; $i += 2) {
|
||||
$sum += intval($code[$i]);
|
||||
}
|
||||
$r = $sum % 10;
|
||||
if ($r > 0) {
|
||||
$r = (10 - $r);
|
||||
}
|
||||
|
||||
return strval($r);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
/*
|
||||
* Standard 2 of 5 barcodes.
|
||||
* Used in airline ticket marking, photofinishing
|
||||
* Contains digits (0 to 9) and encodes the data only in the width of bars.
|
||||
*/
|
||||
|
||||
class TypeStandard2of5Checksum extends TypeStandard2of5
|
||||
{
|
||||
protected bool $checksum = true;
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
/**
|
||||
* Adapted by Darren Stephens <[email protected]>
|
||||
* from Java implementation of Telepen by <[email protected]> Robin Stuart
|
||||
* at https://github.com/woo-j/OkapiBarcode which uses the
|
||||
* Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Implements Telepen (also known as Telepen Alpha), and Telepen Numeric.
|
||||
*
|
||||
* Telepen can encode ASCII text input and includes a modulo-127 check digit.
|
||||
* Telepen Numeric allows compression of numeric data into a Telepen symbol. Data
|
||||
* can consist of pairs of numbers or pairs consisting of a numerical digit followed
|
||||
* by an X character. Telepen Numeric also includes a mod-127 check digit.
|
||||
*/
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\BarcodeBar;
|
||||
use Picqer\Barcode\Exceptions\InvalidFormatException;
|
||||
|
||||
class TypeTelepen implements TypeInterface
|
||||
{
|
||||
private const TELEPEN_START_CHAR = '_';
|
||||
private const TELEPEN_STOP_CHAR = 'z';
|
||||
|
||||
private const TELEPEN_ALPHA = 'alpha';
|
||||
private const TELEPEN_NUMERIC = 'numeric';
|
||||
|
||||
private array $telepen_lookup_table;
|
||||
private string $mode;
|
||||
|
||||
public function __construct($m = 'alpha')
|
||||
{
|
||||
$this->mode = self::TELEPEN_ALPHA;
|
||||
if (strtolower($m) == 'numeric') {
|
||||
$this->mode = self::TELEPEN_NUMERIC;
|
||||
}
|
||||
$this->createTelepenConversionTable();
|
||||
}
|
||||
|
||||
public function getBarcode(string $code): Barcode
|
||||
{
|
||||
/* The stream we get from the telepen output gives us the
|
||||
* width of alternating black/white stripes
|
||||
*/
|
||||
|
||||
$encoded = $this->encode($code); //binary string
|
||||
$barcode = new Barcode($code);
|
||||
|
||||
$drawBar = true;
|
||||
for ($i = 0; $i < strlen($encoded); ++$i) {
|
||||
$barWidth = $encoded[$i];
|
||||
$barcode->addBar(new BarcodeBar(intval($barWidth), 250, $drawBar));
|
||||
$drawBar = !$drawBar; //flip to other colour
|
||||
}
|
||||
|
||||
return $barcode;
|
||||
}
|
||||
|
||||
protected function encode($code) : string
|
||||
{
|
||||
if ($this->mode == self::TELEPEN_ALPHA) {
|
||||
$result = $this->encodeAlpha($code);
|
||||
} else {
|
||||
$result = $this->encodeNumeric($code);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function encodeAlpha($code) : string
|
||||
{
|
||||
// We aren't interested in the non-printable parts of the ASCII set
|
||||
if (
|
||||
!preg_match('/[ -~]+/', $code)
|
||||
) { // everything from ASCII32-ASCII127
|
||||
throw new InvalidFormatException("Invalid characters in data");
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
|
||||
/* other implementations use the byte-chr-int type equivalence to work
|
||||
* with array indices in the conversion/lookup table. It's probably
|
||||
* better to be more explicit with php, hence the use of ord and chr here.
|
||||
*/
|
||||
|
||||
// begin with start char
|
||||
$dest = $this->telepen_lookup_table[ord(self::TELEPEN_START_CHAR)];
|
||||
|
||||
for ($i = 0; $i < strlen($code); $i++) {
|
||||
//$ascii_code = ord(substr($code, $i, 1));
|
||||
$ascii_code = ord($code[$i]);
|
||||
$dest .= ($this->telepen_lookup_table[$ascii_code]);
|
||||
$count += $ascii_code;
|
||||
}
|
||||
|
||||
// Now add check and terminator
|
||||
$check_digit = 127 - ($count % 127);
|
||||
if ($check_digit == 127) {
|
||||
$check_digit = 0;
|
||||
}
|
||||
|
||||
$dest .= $this->telepen_lookup_table[ord(strval($check_digit))];
|
||||
$dest .= $this->telepen_lookup_table[ord(self::TELEPEN_STOP_CHAR)]; // Stop
|
||||
|
||||
return $dest;
|
||||
}
|
||||
|
||||
private function encodeNumeric(string $code) : string
|
||||
{
|
||||
|
||||
/* If input contains non-numeric or X, exit */
|
||||
if (!preg_match('/^[0-9X]+$/', $code)) {
|
||||
throw new InvalidFormatException("Invalid characters in data");
|
||||
}
|
||||
|
||||
/* If input is an odd length, exit */
|
||||
$t = '';
|
||||
if (strlen($code) % 2 > 0) {
|
||||
throw new InvalidFormatException("There must be an even number of digits");
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
$dest = $this->telepen_lookup_table[ord(self::TELEPEN_START_CHAR)]; // begin with the start character _
|
||||
|
||||
for ($i = 0; $i < strlen($code); $i += 2) {
|
||||
$c1 = $code[$i];
|
||||
$c2 = $code[$i+1];
|
||||
/* Input nX is allowed, but Xn is not */
|
||||
if ($c1 == 'X') {
|
||||
throw new InvalidFormatException("Invalid position of X in data");
|
||||
}
|
||||
$glyph = null;
|
||||
if ($c2 == 'X') {
|
||||
$glyph = (ord($c1) - ord('0')) + 17;
|
||||
} else {
|
||||
$glyph = ((10 * (ord($c1) - ord('0'))) + (ord($c2) - ord('0'))) + 27;
|
||||
}
|
||||
$count += $glyph;
|
||||
$dest .= $this->telepen_lookup_table[$glyph];
|
||||
}
|
||||
|
||||
$check_digit = 127 - ($count % 127);
|
||||
if ($check_digit == 127) {
|
||||
$check_digit = 0;
|
||||
}
|
||||
|
||||
$dest .= $this->telepen_lookup_table[$check_digit];
|
||||
$dest .= $this->telepen_lookup_table[ord(self::TELEPEN_STOP_CHAR)]; // Stop
|
||||
|
||||
return $dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* The table provides a representation of barcode patterns
|
||||
* for each character in the ASCII set. from ASCII0-127
|
||||
* Each barcode starts with "_" - ASCII95 0x5F,
|
||||
* and ends with "z" - ASCII122 0xFA.
|
||||
* More information about Telepen symbology is available from
|
||||
* https://v4l237.n3cdn1.secureserver.net/wp-content/uploads/2022/05/Barcode-Symbology-information-and-History.pdf
|
||||
*/
|
||||
private function createTelepenConversionTable(): void
|
||||
{
|
||||
$this->telepen_lookup_table = [
|
||||
"1111111111111111", "1131313111", "33313111", "1111313131",
|
||||
"3111313111", "11333131", "13133131", "111111313111",
|
||||
"31333111", "1131113131", "33113131", "1111333111",
|
||||
"3111113131", "1113133111", "1311133111", "111111113131",
|
||||
"3131113111", "11313331", "333331", "111131113111",
|
||||
"31113331", "1133113111", "1313113111", "1111113331",
|
||||
"31131331", "113111113111", "3311113111", "1111131331",
|
||||
"311111113111", "1113111331", "1311111331", "11111111113111",
|
||||
"31313311", "1131311131", "33311131", "1111313311",
|
||||
"3111311131", "11333311", "13133311", "111111311131",
|
||||
"31331131", "1131113311", "33113311", "1111331131",
|
||||
"3111113311", "1113131131", "1311131131", "111111113311",
|
||||
"3131111131", "1131131311", "33131311", "111131111131",
|
||||
"3111131311", "1133111131", "1313111131", "111111131311",
|
||||
"3113111311", "113111111131", "3311111131", "111113111311",
|
||||
"311111111131", "111311111311", "131111111311", "11111111111131",
|
||||
"3131311111", "11313133", "333133", "111131311111",
|
||||
"31113133", "1133311111", "1313311111", "1111113133",
|
||||
"313333", "113111311111", "3311311111", "11113333",
|
||||
"311111311111", "11131333", "13111333", "11111111311111",
|
||||
"31311133", "1131331111", "33331111", "1111311133",
|
||||
"3111331111", "11331133", "13131133", "111111331111",
|
||||
"3113131111", "1131111133", "33111133", "111113131111",
|
||||
"3111111133", "111311131111", "131111131111", "111111111133",
|
||||
"31311313", "113131111111", "3331111111", "1111311313",
|
||||
"311131111111", "11331313", "13131313", "11111131111111",
|
||||
"3133111111", "1131111313", "33111313", "111133111111",
|
||||
"3111111313", "111313111111", "131113111111", "111111111313",
|
||||
"313111111111", "1131131113", "33131113", "11113111111111",
|
||||
"3111131113", "113311111111", "131311111111", "111111131113",
|
||||
"3113111113", "11311111111111", "331111111111", "111113111113",
|
||||
"31111111111111", "111311111113", "131111111113"
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Adapted by Darren Stephens <[email protected]>
|
||||
* from Java implementation of Telepen by <[email protected]> Robin Stuart
|
||||
* at https://github.com/woo-j/OkapiBarcode which uses the
|
||||
* Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Implements Telepen (also known as Telepen Alpha), and Telepen Numeric.
|
||||
*
|
||||
* Telepen can encode ASCII text input and includes a modulo-127 check digit.
|
||||
* Telepen Numeric allows compression of numeric data into a Telepen symbol. Data
|
||||
* can consist of pairs of numbers or pairs consisting of a numerical digit followed
|
||||
* by an X character. Telepen Numeric also includes a mod-127 check digit.
|
||||
*/
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
class TypeTelepenNumeric extends TypeTelepen
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('numeric');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
/*
|
||||
* EAN13 and UPC-A barcodes.
|
||||
* EAN13: European Article Numbering international retail product code
|
||||
* UPC-A: Universal product code seen on almost all retail products in the USA and Canada
|
||||
* UPC-E: Short version of UPC symbol
|
||||
*
|
||||
* @param $code (string) code to represent.
|
||||
* @param $len (string) barcode type: 6 = UPC-E, 8 = EAN8, 13 = EAN13, 12 = UPC-A
|
||||
*/
|
||||
|
||||
class TypeUpcA extends TypeEanUpcBase
|
||||
{
|
||||
protected int $length = 12;
|
||||
protected bool $upca = true;
|
||||
protected bool $upce = false;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
/*
|
||||
* EAN13 and UPC-A barcodes.
|
||||
* EAN13: European Article Numbering international retail product code
|
||||
* UPC-A: Universal product code seen on almost all retail products in the USA and Canada
|
||||
* UPC-E: Short version of UPC symbol
|
||||
*
|
||||
* @param $code (string) code to represent.
|
||||
* @param $len (string) barcode type: 6 = UPC-E, 8 = EAN8, 13 = EAN13, 12 = UPC-A
|
||||
*/
|
||||
|
||||
class TypeUpcE extends TypeEanUpcBase
|
||||
{
|
||||
protected int $length = 12;
|
||||
protected bool $upca = false;
|
||||
protected bool $upce = true;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
use Picqer\Barcode\Barcode;
|
||||
use Picqer\Barcode\Exceptions\InvalidCheckDigitException;
|
||||
use Picqer\Barcode\Helpers\BinarySequenceConverter;
|
||||
|
||||
/*
|
||||
* UPC-Based Extensions
|
||||
* 2-Digit Ext.: Used to indicate magazines and newspaper issue numbers
|
||||
* 5-Digit Ext.: Used to mark suggested retail price of books
|
||||
*/
|
||||
|
||||
class TypeUpcExtension2 implements TypeInterface
|
||||
{
|
||||
protected int $length = 2;
|
||||
|
||||
public function getBarcode(string $code): Barcode
|
||||
{
|
||||
$len = $this->length;
|
||||
|
||||
// Padding
|
||||
$code = str_pad($code, $len, '0', STR_PAD_LEFT);
|
||||
|
||||
// Calculate check digit
|
||||
if ($len == 2) {
|
||||
$r = (int)$code % 4;
|
||||
} elseif ($len == 5) {
|
||||
$r = (3 * intval($code[0] . $code[2] . $code[4])) + (9 * intval($code[1] . $code[3]));
|
||||
$r %= 10;
|
||||
} else {
|
||||
throw new InvalidCheckDigitException();
|
||||
}
|
||||
|
||||
// Convert digits to bars
|
||||
$codes = [
|
||||
'A' => [ // left odd parity
|
||||
'0' => '0001101',
|
||||
'1' => '0011001',
|
||||
'2' => '0010011',
|
||||
'3' => '0111101',
|
||||
'4' => '0100011',
|
||||
'5' => '0110001',
|
||||
'6' => '0101111',
|
||||
'7' => '0111011',
|
||||
'8' => '0110111',
|
||||
'9' => '0001011'
|
||||
],
|
||||
'B' => [ // left even parity
|
||||
'0' => '0100111',
|
||||
'1' => '0110011',
|
||||
'2' => '0011011',
|
||||
'3' => '0100001',
|
||||
'4' => '0011101',
|
||||
'5' => '0111001',
|
||||
'6' => '0000101',
|
||||
'7' => '0010001',
|
||||
'8' => '0001001',
|
||||
'9' => '0010111'
|
||||
]
|
||||
];
|
||||
|
||||
$parities = [
|
||||
2 =>[
|
||||
'0' => ['A', 'A'],
|
||||
'1' => ['A', 'B'],
|
||||
'2' => ['B', 'A'],
|
||||
'3' => ['B', 'B']
|
||||
],
|
||||
5 => [
|
||||
'0' => ['B', 'B', 'A', 'A', 'A'],
|
||||
'1' => ['B', 'A', 'B', 'A', 'A'],
|
||||
'2' => ['B', 'A', 'A', 'B', 'A'],
|
||||
'3' => ['B', 'A', 'A', 'A', 'B'],
|
||||
'4' => ['A', 'B', 'B', 'A', 'A'],
|
||||
'5' => ['A', 'A', 'B', 'B', 'A'],
|
||||
'6' => ['A', 'A', 'A', 'B', 'B'],
|
||||
'7' => ['A', 'B', 'A', 'B', 'A'],
|
||||
'8' => ['A', 'B', 'A', 'A', 'B'],
|
||||
'9' => ['A', 'A', 'B', 'A', 'B']
|
||||
]
|
||||
];
|
||||
|
||||
$p = $parities[$len][$r];
|
||||
$seq = '1011'; // left guard bar
|
||||
$seq .= $codes[$p[0]][$code[0]];
|
||||
for ($i = 1; $i < $len; ++$i) {
|
||||
$seq .= '01'; // separator
|
||||
$seq .= $codes[$p[$i]][$code[$i]];
|
||||
}
|
||||
|
||||
return BinarySequenceConverter::convert($code, $seq);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Picqer\Barcode\Types;
|
||||
|
||||
/*
|
||||
* UPC-Based Extensions
|
||||
* 2-Digit Ext.: Used to indicate magazines and newspaper issue numbers
|
||||
* 5-Digit Ext.: Used to mark suggested retail price of books
|
||||
*/
|
||||
|
||||
class TypeUpcExtension5 extends TypeUpcExtension2
|
||||
{
|
||||
protected int $length = 5;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BarcodeDynamicHtmlTest extends TestCase
|
||||
{
|
||||
public function test_dynamic_html_barcode_generator_can_generate_code_128_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorDynamicHTML();
|
||||
$generated = $generator->getBarcode('081231723897', $generator::TYPE_CODE_128);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/081231723897-dynamic-code128.html', $generated);
|
||||
}
|
||||
|
||||
public function test_dynamic_html_barcode_generator_can_generate_imb_barcode_to_test_heights()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorDynamicHTML();
|
||||
$generated = $generator->getBarcode('12345678903', $generator::TYPE_IMB);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/12345678903-dynamic-imb.html', $generated);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BarcodeHtmlTest extends TestCase
|
||||
{
|
||||
public function test_html_barcode_generator_can_generate_code_128_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorHTML();
|
||||
$generated = $generator->getBarcode('081231723897', $generator::TYPE_CODE_128);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/081231723897-code128.html', $generated);
|
||||
}
|
||||
|
||||
public function test_html_barcode_generator_can_generate_imb_barcode_to_test_heights()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorHTML();
|
||||
$generated = $generator->getBarcode('12345678903', $generator::TYPE_IMB);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/12345678903-imb.html', $generated);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BarcodeJpgTest extends TestCase
|
||||
{
|
||||
public function test_jpg_barcode_generator_can_generate_code_128_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorJPG();
|
||||
$generator->useGd();
|
||||
$result = $generator->getBarcode('081231723897', $generator::TYPE_CODE_128);
|
||||
|
||||
$imageInfo = getimagesizefromstring($result);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
$this->assertEquals(202, $imageInfo[0]); // Image width
|
||||
$this->assertEquals(30, $imageInfo[1]); // Image height
|
||||
$this->assertEquals('image/jpeg', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
public function test_jpg_barcode_generator_can_generate_code_39_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorJPG();
|
||||
$generator->useGd();
|
||||
$result = $generator->getBarcode('081231723897', $generator::TYPE_CODE_39, 1);
|
||||
|
||||
$imageInfo = getimagesizefromstring($result);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
$this->assertEquals(224, $imageInfo[0]); // Image width
|
||||
$this->assertEquals(30, $imageInfo[1]); // Image height
|
||||
$this->assertEquals('image/jpeg', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
public function test_jpg_barcode_generator_can_use_different_height()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorJPG();
|
||||
$generator->useGd();
|
||||
$result = $generator->getBarcode('081231723897', $generator::TYPE_CODE_128, 2, 45);
|
||||
|
||||
$imageInfo = getimagesizefromstring($result);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
$this->assertEquals(202, $imageInfo[0]); // Image width
|
||||
$this->assertEquals(45, $imageInfo[1]); // Image height
|
||||
$this->assertEquals('image/jpeg', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
public function test_jpg_barcode_generator_can_use_different_width_factor()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorJPG();
|
||||
$generator->useGd();
|
||||
$result = $generator->getBarcode('081231723897', $generator::TYPE_CODE_128, 5);
|
||||
|
||||
$imageInfo = getimagesizefromstring($result);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
$this->assertEquals(505, $imageInfo[0]); // Image width
|
||||
$this->assertEquals('image/jpeg', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
|
||||
// Copied as Imagick
|
||||
|
||||
public function test_jpg_barcode_generator_can_generate_code_128_barcode_imagick()
|
||||
{
|
||||
if (! extension_loaded('imagick')) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorJPG();
|
||||
$generator->useImagick();
|
||||
$result = $generator->getBarcode('081231723897', $generator::TYPE_CODE_128);
|
||||
|
||||
$imageInfo = getimagesizefromstring($result);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
$this->assertEquals(202, $imageInfo[0]); // Image width
|
||||
$this->assertEquals(30, $imageInfo[1]); // Image height
|
||||
$this->assertEquals('image/jpeg', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
public function test_jpg_barcode_generator_can_generate_code_39_barcode_imagick()
|
||||
{
|
||||
if (! extension_loaded('imagick')) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorJPG();
|
||||
$generator->useImagick();
|
||||
$result = $generator->getBarcode('081231723897', $generator::TYPE_CODE_39, 1);
|
||||
|
||||
$imageInfo = getimagesizefromstring($result);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
$this->assertEquals(224, $imageInfo[0]); // Image width
|
||||
$this->assertEquals(30, $imageInfo[1]); // Image height
|
||||
$this->assertEquals('image/jpeg', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
public function test_jpg_barcode_generator_can_use_different_height_imagick()
|
||||
{
|
||||
if (! extension_loaded('imagick')) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorJPG();
|
||||
$generator->useImagick();
|
||||
$result = $generator->getBarcode('081231723897', $generator::TYPE_CODE_128, 2, 45);
|
||||
|
||||
$imageInfo = getimagesizefromstring($result);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
$this->assertEquals(202, $imageInfo[0]); // Image width
|
||||
$this->assertEquals(45, $imageInfo[1]); // Image height
|
||||
$this->assertEquals('image/jpeg', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
public function test_jpg_barcode_generator_can_use_different_width_factor_imagick()
|
||||
{
|
||||
if (! extension_loaded('imagick')) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorJPG();
|
||||
$generator->useImagick();
|
||||
$result = $generator->getBarcode('081231723897', $generator::TYPE_CODE_128, 5);
|
||||
|
||||
$imageInfo = getimagesizefromstring($result);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
$this->assertEquals(505, $imageInfo[0]); // Image width
|
||||
$this->assertEquals('image/jpeg', $imageInfo['mime']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BarcodePngTest extends TestCase
|
||||
{
|
||||
public function test_png_barcode_generator_can_generate_code_128_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorPNG();
|
||||
$generator->useGd();
|
||||
$generated = $generator->getBarcode('081231723897', $generator::TYPE_CODE_128);
|
||||
|
||||
$this->assertEquals('PNG', substr($generated, 1, 3));
|
||||
}
|
||||
|
||||
public function test_png_barcode_generator_can_generate_code_39_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorPNG();
|
||||
$generator->useGd();
|
||||
$result = $generator->getBarcode('081231723897', $generator::TYPE_CODE_39, 1);
|
||||
|
||||
$imageInfo = getimagesizefromstring($result);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
$this->assertEquals(224, $imageInfo[0]); // Image width
|
||||
$this->assertEquals(30, $imageInfo[1]); // Image height
|
||||
$this->assertEquals('image/png', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
public function test_png_barcode_generator_can_use_different_height()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorPNG();
|
||||
$generator->useGd();
|
||||
$result = $generator->getBarcode('081231723897', $generator::TYPE_CODE_128, 2, 45);
|
||||
|
||||
$imageInfo = getimagesizefromstring($result);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
$this->assertEquals(202, $imageInfo[0]); // Image width
|
||||
$this->assertEquals(45, $imageInfo[1]); // Image height
|
||||
$this->assertEquals('image/png', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
public function test_png_barcode_generator_can_use_different_width_factor()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorPNG();
|
||||
$generator->useGd();
|
||||
$result = $generator->getBarcode('081231723897', $generator::TYPE_CODE_128, 5);
|
||||
|
||||
$imageInfo = getimagesizefromstring($result);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
$this->assertEquals(505, $imageInfo[0]); // Image width
|
||||
$this->assertEquals('image/png', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
|
||||
// Copied as Imagick
|
||||
|
||||
public function test_png_barcode_generator_can_generate_code_128_barcode_imagick()
|
||||
{
|
||||
if (! extension_loaded('imagick')) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorPNG();
|
||||
$generator->useImagick();
|
||||
$generated = $generator->getBarcode('081231723897', $generator::TYPE_CODE_128);
|
||||
|
||||
$this->assertEquals('PNG', substr($generated, 1, 3));
|
||||
}
|
||||
|
||||
public function test_png_barcode_generator_can_generate_code_39_barcode_imagick()
|
||||
{
|
||||
if (! extension_loaded('imagick')) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorPNG();
|
||||
$generator->useImagick();
|
||||
$result = $generator->getBarcode('081231723897', $generator::TYPE_CODE_39, 1);
|
||||
|
||||
$imageInfo = getimagesizefromstring($result);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
$this->assertEquals(224, $imageInfo[0]); // Image width
|
||||
$this->assertEquals(30, $imageInfo[1]); // Image height
|
||||
$this->assertEquals('image/png', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
public function test_png_barcode_generator_can_use_different_height_imagick()
|
||||
{
|
||||
if (! extension_loaded('imagick')) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorPNG();
|
||||
$generator->useImagick();
|
||||
$result = $generator->getBarcode('081231723897', $generator::TYPE_CODE_128, 2, 45);
|
||||
|
||||
$imageInfo = getimagesizefromstring($result);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
$this->assertEquals(202, $imageInfo[0]); // Image width
|
||||
$this->assertEquals(45, $imageInfo[1]); // Image height
|
||||
$this->assertEquals('image/png', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
public function test_png_barcode_generator_can_use_different_width_factor_imagick()
|
||||
{
|
||||
if (! extension_loaded('imagick')) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorPNG();
|
||||
$generator->useImagick();
|
||||
$result = $generator->getBarcode('081231723897', $generator::TYPE_CODE_128, 5);
|
||||
|
||||
$imageInfo = getimagesizefromstring($result);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
$this->assertEquals(505, $imageInfo[0]); // Image width
|
||||
$this->assertEquals('image/png', $imageInfo['mime']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BarcodeSvgTest extends TestCase
|
||||
{
|
||||
public function test_svg_barcode_generator_can_generate_ean_13_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$generated = $generator->getBarcode('081231723897', $generator::TYPE_EAN_13);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/081231723897-ean13.svg', $generated);
|
||||
}
|
||||
|
||||
public function test_svg_barcode_generator_can_generate_ean_13_barcode_with_fractional_width()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$generated = $generator->getBarcode('081231723897', $generator::TYPE_EAN_13, 0.25, 25.75);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/081231723897-ean13-fractional-width.svg', $generated);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Picqer\Barcode\Exceptions\BarcodeException;
|
||||
use Picqer\Barcode\Exceptions\InvalidCheckDigitException;
|
||||
use Picqer\Barcode\Types\TypeEan13;
|
||||
use Picqer\Barcode\Types\TypeInterface;
|
||||
use Picqer\Barcode\Types\TypeITF14;
|
||||
|
||||
class ChecksumBarcodeTest extends TestCase
|
||||
{
|
||||
private const VALID_BARCODES = [
|
||||
['type' => TypeEan13::class, 'barcodes' => [
|
||||
'081231723897' => '0812317238973',
|
||||
'004900000463' => '0049000004632',
|
||||
]],
|
||||
['type' => TypeITF14::class, 'barcodes' => [
|
||||
'0001234560001' => '00012345600012',
|
||||
'0540014128876' => '05400141288766',
|
||||
]],
|
||||
];
|
||||
private const INVALID_BARCODES = [
|
||||
['type' => TypeEan13::class, 'barcodes' => ['0812317238972', '0049000004633']],
|
||||
['type' => TypeITF14::class, 'barcodes' => ['00012345600016', '05400141288762']],
|
||||
];
|
||||
|
||||
public function testAllValidBarcodeTypes()
|
||||
{
|
||||
foreach (self::VALID_BARCODES as $barcodeTestSet) {
|
||||
$barcodeType = $this->getBarcodeType($barcodeTestSet['type']);
|
||||
|
||||
foreach ($barcodeTestSet['barcodes'] as $testBarcode => $validBarcode) {
|
||||
$this->assertEquals($validBarcode, $barcodeType->getBarcode($testBarcode)->getBarcode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testAllInvalidBarcodeTypes()
|
||||
{
|
||||
foreach (self::INVALID_BARCODES as $barcodeTestSet) {
|
||||
$barcodeType = $this->getBarcodeType($barcodeTestSet['type']);
|
||||
|
||||
foreach ($barcodeTestSet['barcodes'] as $invalidBarcode) {
|
||||
try {
|
||||
$barcodeType->getBarcode($invalidBarcode)->getBarcode();
|
||||
} catch (BarcodeException $exception) {
|
||||
$this->assertInstanceOf(InvalidCheckDigitException::class, $exception);
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->assertTrue(false, sprintf('Exception was not thrown for barcode "%s".', $invalidBarcode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getBarcodeType(string $typeClass): TypeInterface
|
||||
{
|
||||
return new $typeClass;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DynamicHtmlRendererTest extends TestCase
|
||||
{
|
||||
public function test_dynamic_html_barcode_generator_can_generate_code_128_barcode()
|
||||
{
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode128())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\DynamicHtmlRenderer();
|
||||
$generated = $renderer->render($barcode);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/081231723897-dynamic-code128.html', $generated);
|
||||
}
|
||||
|
||||
public function test_dynamic_html_barcode_generator_can_generate_imb_barcode_to_test_heights()
|
||||
{
|
||||
$barcode = (new Picqer\Barcode\Types\TypeIntelligentMailBarcode())->getBarcode('12345678903');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\DynamicHtmlRenderer();
|
||||
$generated = $renderer->render($barcode);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/12345678903-dynamic-imb.html', $generated);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class GeneratorTest extends TestCase
|
||||
{
|
||||
public function test_throws_exception_if_empty_barcode_is_used_in_ean13()
|
||||
{
|
||||
$this->expectException(Picqer\Barcode\Exceptions\InvalidLengthException::class);
|
||||
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$generator->getBarcode('', $generator::TYPE_EAN_13);
|
||||
}
|
||||
|
||||
public function test_throws_exception_if_empty_barcode_is_used_in_code128()
|
||||
{
|
||||
$this->expectException(Picqer\Barcode\Exceptions\InvalidLengthException::class);
|
||||
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$generator->getBarcode('', $generator::TYPE_CODE_128);
|
||||
}
|
||||
|
||||
public function test_ean13_generator_throws_exception_if_invalid_chars_are_used()
|
||||
{
|
||||
$this->expectException(Picqer\Barcode\Exceptions\InvalidCharacterException::class);
|
||||
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$generator->getBarcode('A123', $generator::TYPE_EAN_13);
|
||||
}
|
||||
|
||||
public function test_ean13_generator_accepting_13_chars()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$generated = $generator->getBarcode('0049000004632', $generator::TYPE_EAN_13);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/0049000004632-ean13.svg', $generated);
|
||||
}
|
||||
|
||||
public function test_ean13_generator_accepting_12_chars_and_generates_13th_check_digit()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$generated = $generator->getBarcode('004900000463', $generator::TYPE_EAN_13);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/0049000004632-ean13.svg', $generated);
|
||||
}
|
||||
|
||||
public function test_ean13_generator_accepting_11_chars_and_generates_13th_check_digit_and_adds_leading_zero()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$generated = $generator->getBarcode('04900000463', $generator::TYPE_EAN_13);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/0049000004632-ean13.svg', $generated);
|
||||
}
|
||||
|
||||
public function test_ean13_generator_throws_exception_when_wrong_check_digit_is_given()
|
||||
{
|
||||
$this->expectException(Picqer\Barcode\Exceptions\InvalidCheckDigitException::class);
|
||||
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$generator->getBarcode('0049000004633', $generator::TYPE_EAN_13);
|
||||
}
|
||||
|
||||
public function test_generator_throws_unknown_type_exceptions()
|
||||
{
|
||||
$this->expectException(Picqer\Barcode\Exceptions\UnknownTypeException::class);
|
||||
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$generator->getBarcode('0049000004633', 'vladimir');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class HtmlRendererTest extends TestCase
|
||||
{
|
||||
public function test_html_barcode_generator_can_generate_code_128_barcode()
|
||||
{
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode128())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\HtmlRenderer();
|
||||
$generated = $renderer->render($barcode, $barcode->getWidth() * 2);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/081231723897-code128.html', $generated);
|
||||
}
|
||||
|
||||
public function test_html_barcode_generator_can_generate_imb_barcode_to_test_heights()
|
||||
{
|
||||
$barcode = (new Picqer\Barcode\Types\TypeIntelligentMailBarcode())->getBarcode('12345678903');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\HtmlRenderer();
|
||||
$generated = $renderer->render($barcode, $barcode->getWidth() * 2);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/12345678903-imb.html', $generated);
|
||||
}
|
||||
|
||||
public function test_html_barcode_generator_with_background()
|
||||
{
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode128())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\HtmlRenderer();
|
||||
$renderer->setBackgroundColor([255, 0, 0]);
|
||||
$generated = $renderer->render($barcode, $barcode->getWidth() * 2);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/081231723897-code128-red-background.html', $generated);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class JpgRendererTest extends TestCase
|
||||
{
|
||||
public function test_jpg_barcode_generator_can_generate_code_128_barcode()
|
||||
{
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode128())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\JpgRenderer();
|
||||
$renderer->useGd();
|
||||
$generated = $renderer->render($barcode, $barcode->getWidth() * 2);
|
||||
|
||||
$imageInfo = getimagesizefromstring($generated);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($generated));
|
||||
$this->assertEquals(202, $imageInfo[0]); // Image width
|
||||
$this->assertEquals(30, $imageInfo[1]); // Image height
|
||||
$this->assertEquals('image/jpeg', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
|
||||
public function test_jpg_barcode_generator_can_generate_code_39_barcode()
|
||||
{
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode39())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\JpgRenderer();
|
||||
$renderer->useGd();
|
||||
$generated = $renderer->render($barcode, $barcode->getWidth());
|
||||
|
||||
$imageInfo = getimagesizefromstring($generated);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($generated));
|
||||
$this->assertEquals(224, $imageInfo[0]); // Image width
|
||||
$this->assertEquals(30, $imageInfo[1]); // Image height
|
||||
$this->assertEquals('image/jpeg', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
public function test_jpg_barcode_generator_can_use_different_height()
|
||||
{
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode128())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\JpgRenderer();
|
||||
$renderer->useGd();
|
||||
$generated = $renderer->render($barcode, $barcode->getWidth() * 2, 45);
|
||||
|
||||
$imageInfo = getimagesizefromstring($generated);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($generated));
|
||||
$this->assertEquals(202, $imageInfo[0]); // Image width
|
||||
$this->assertEquals(45, $imageInfo[1]); // Image height
|
||||
$this->assertEquals('image/jpeg', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
public function test_jpg_barcode_generator_can_use_different_width_factor()
|
||||
{
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode128())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\JpgRenderer();
|
||||
$renderer->useGd();
|
||||
$generated = $renderer->render($barcode, $barcode->getWidth() * 5);
|
||||
|
||||
$imageInfo = getimagesizefromstring($generated);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($generated));
|
||||
$this->assertEquals(505, $imageInfo[0]); // Image width
|
||||
$this->assertEquals('image/jpeg', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
|
||||
// Copied as Imagick
|
||||
|
||||
public function test_jpg_barcode_generator_can_generate_code_128_barcode_imagick()
|
||||
{
|
||||
if (! extension_loaded('imagick')) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode128())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\JpgRenderer();
|
||||
$renderer->useImagick();
|
||||
$generated = $renderer->render($barcode, $barcode->getWidth() * 2);
|
||||
|
||||
$imageInfo = getimagesizefromstring($generated);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($generated));
|
||||
$this->assertEquals(202, $imageInfo[0]); // Image width
|
||||
$this->assertEquals(30, $imageInfo[1]); // Image height
|
||||
$this->assertEquals('image/jpeg', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
public function test_jpg_barcode_generator_can_generate_code_39_barcode_imagick()
|
||||
{
|
||||
if (! extension_loaded('imagick')) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode39())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\JpgRenderer();
|
||||
$renderer->useImagick();
|
||||
$generated = $renderer->render($barcode, $barcode->getWidth());
|
||||
|
||||
$imageInfo = getimagesizefromstring($generated);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($generated));
|
||||
$this->assertEquals(224, $imageInfo[0]); // Image width
|
||||
$this->assertEquals(30, $imageInfo[1]); // Image height
|
||||
$this->assertEquals('image/jpeg', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
public function test_jpg_barcode_generator_can_use_different_height_imagick()
|
||||
{
|
||||
if (! extension_loaded('imagick')) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode128())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\JpgRenderer();
|
||||
$renderer->useGd();
|
||||
$generated = $renderer->render($barcode, $barcode->getWidth() * 2, 45);
|
||||
|
||||
$imageInfo = getimagesizefromstring($generated);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($generated));
|
||||
$this->assertEquals(202, $imageInfo[0]); // Image width
|
||||
$this->assertEquals(45, $imageInfo[1]); // Image height
|
||||
$this->assertEquals('image/jpeg', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
public function test_jpg_barcode_generator_can_use_different_width_factor_imagick()
|
||||
{
|
||||
if (! extension_loaded('imagick')) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode128())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\JpgRenderer();
|
||||
$renderer->useGd();
|
||||
$generated = $renderer->render($barcode, $barcode->getWidth() * 5);
|
||||
|
||||
$imageInfo = getimagesizefromstring($generated);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($generated));
|
||||
$this->assertEquals(505, $imageInfo[0]); // Image width
|
||||
$this->assertEquals('image/jpeg', $imageInfo['mime']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class PharmacodeTest extends TestCase
|
||||
{
|
||||
public function test_validation_triggerd_when_generating_zero_code()
|
||||
{
|
||||
$pharmacode = new Picqer\Barcode\Types\TypePharmacodeTwoCode();
|
||||
|
||||
$this->expectException(Picqer\Barcode\Exceptions\InvalidLengthException::class);
|
||||
|
||||
$pharmacode->getBarcode('0');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class PngRendererTest extends TestCase
|
||||
{
|
||||
public function test_png_barcode_generator_can_generate_code_128_barcode()
|
||||
{
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode128())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\PngRenderer();
|
||||
$renderer->useGd();
|
||||
$generated = $renderer->render($barcode);
|
||||
|
||||
$this->assertEquals('PNG', substr($generated, 1, 3));
|
||||
}
|
||||
|
||||
|
||||
public function test_png_barcode_generator_can_generate_code_39_barcode()
|
||||
{
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode39())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\PngRenderer();
|
||||
$renderer->useGd();
|
||||
$generated = $renderer->render($barcode, $barcode->getWidth());
|
||||
|
||||
$imageInfo = getimagesizefromstring($generated);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($generated));
|
||||
$this->assertEquals(224, $imageInfo[0]); // Image width
|
||||
$this->assertEquals(30, $imageInfo[1]); // Image height
|
||||
$this->assertEquals('image/png', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
public function test_png_barcode_generator_can_use_different_height()
|
||||
{
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode128())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\PngRenderer();
|
||||
$renderer->useGd();
|
||||
$generated = $renderer->render($barcode, $barcode->getWidth() * 2, 45);
|
||||
|
||||
$imageInfo = getimagesizefromstring($generated);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($generated));
|
||||
$this->assertEquals(202, $imageInfo[0]); // Image width
|
||||
$this->assertEquals(45, $imageInfo[1]); // Image height
|
||||
$this->assertEquals('image/png', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
public function test_png_barcode_generator_can_use_different_width_factor()
|
||||
{
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode128())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\PngRenderer();
|
||||
$renderer->useGd();
|
||||
$generated = $renderer->render($barcode, $barcode->getWidth() * 5);
|
||||
|
||||
$imageInfo = getimagesizefromstring($generated);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($generated));
|
||||
$this->assertEquals(505, $imageInfo[0]); // Image width
|
||||
$this->assertEquals('image/png', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
|
||||
// Copied as Imagick
|
||||
|
||||
public function test_png_barcode_generator_can_generate_code_128_barcode_imagick()
|
||||
{
|
||||
if (! extension_loaded('imagick')) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode128())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\PngRenderer();
|
||||
$renderer->useImagick();
|
||||
$generated = $renderer->render($barcode, $barcode->getWidth() * 2);
|
||||
|
||||
$this->assertEquals('PNG', substr($generated, 1, 3));
|
||||
}
|
||||
|
||||
public function test_png_barcode_generator_can_generate_code_39_barcode_imagick()
|
||||
{
|
||||
if (! extension_loaded('imagick')) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode39())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\PngRenderer();
|
||||
$renderer->useImagick();
|
||||
$generated = $renderer->render($barcode, $barcode->getWidth());
|
||||
|
||||
$imageInfo = getimagesizefromstring($generated);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($generated));
|
||||
$this->assertEquals(224, $imageInfo[0]); // Image width
|
||||
$this->assertEquals(30, $imageInfo[1]); // Image height
|
||||
$this->assertEquals('image/png', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
public function test_png_barcode_generator_can_use_different_height_imagick()
|
||||
{
|
||||
if (! extension_loaded('imagick')) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode128())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\PngRenderer();
|
||||
$renderer->useGd();
|
||||
$generated = $renderer->render($barcode, $barcode->getWidth() * 2, 45);
|
||||
|
||||
$imageInfo = getimagesizefromstring($generated);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($generated));
|
||||
$this->assertEquals(202, $imageInfo[0]); // Image width
|
||||
$this->assertEquals(45, $imageInfo[1]); // Image height
|
||||
$this->assertEquals('image/png', $imageInfo['mime']);
|
||||
}
|
||||
|
||||
public function test_png_barcode_generator_can_use_different_width_factor_imagick()
|
||||
{
|
||||
if (! extension_loaded('imagick')) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
$barcode = (new Picqer\Barcode\Types\TypeCode128())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\PngRenderer();
|
||||
$renderer->useGd();
|
||||
$generated = $renderer->render($barcode, $barcode->getWidth() * 5);
|
||||
|
||||
$imageInfo = getimagesizefromstring($generated);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($generated));
|
||||
$this->assertEquals(505, $imageInfo[0]); // Image width
|
||||
$this->assertEquals('image/png', $imageInfo['mime']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SvgRendererTest extends TestCase
|
||||
{
|
||||
public function test_svg_barcode_generator_can_generate_ean_13_barcode()
|
||||
{
|
||||
$barcode = (new Picqer\Barcode\Types\TypeEan13())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\SvgRenderer();
|
||||
$generated = $renderer->render($barcode, 190);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/081231723897-ean13.svg', $generated);
|
||||
}
|
||||
|
||||
public function test_svg_barcode_generator_can_generate_ean_13_barcode_with_fractional_width()
|
||||
{
|
||||
$barcode = (new Picqer\Barcode\Types\TypeEan13())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\SvgRenderer();
|
||||
$generated = $renderer->render($barcode, 23.75, 25.75);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/081231723897-ean13-fractional-width.svg', $generated);
|
||||
}
|
||||
|
||||
public function test_svg_barcode_generator_as_standalone()
|
||||
{
|
||||
$barcode = (new Picqer\Barcode\Types\TypeEan13())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\SvgRenderer();
|
||||
$renderer->setSvgType(\Picqer\Barcode\Renderers\SvgRenderer::TYPE_SVG_STANDALONE);
|
||||
$generated = $renderer->render($barcode);
|
||||
|
||||
$this->assertStringStartsWith('<?xml version="1.0"', $generated);
|
||||
$this->assertStringContainsString('<!DOCTYPE svg PUBLIC', $generated);
|
||||
}
|
||||
|
||||
public function test_svg_barcode_generator_as_inline()
|
||||
{
|
||||
$barcode = (new Picqer\Barcode\Types\TypeEan13())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\SvgRenderer();
|
||||
$renderer->setSvgType(\Picqer\Barcode\Renderers\SvgRenderer::TYPE_SVG_INLINE);
|
||||
$generated = $renderer->render($barcode);
|
||||
|
||||
$this->assertStringStartsWith('<svg width=', $generated);
|
||||
$this->assertStringNotContainsString('<?xml version="1.0"', $generated);
|
||||
$this->assertStringNotContainsString('<!DOCTYPE svg PUBLIC', $generated);
|
||||
}
|
||||
|
||||
public function test_svg_renderer_throws_exception_wrong_type()
|
||||
{
|
||||
$this->expectException(\Picqer\Barcode\Exceptions\InvalidOptionException::class);
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\SvgRenderer();
|
||||
$renderer->setSvgType('other');
|
||||
}
|
||||
|
||||
public function test_svg_barcode_generator_can_use_background_color()
|
||||
{
|
||||
$barcode = (new Picqer\Barcode\Types\TypeEan13())->getBarcode('081231723897');
|
||||
|
||||
$renderer = new Picqer\Barcode\Renderers\SvgRenderer();
|
||||
$renderer->setBackgroundColor([255, 0, 0]);
|
||||
$generated = $renderer->render($barcode, 190);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/081231723897-ean13-red-background.svg', $generated);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Picqer\Barcode\Renderers\SvgRenderer;
|
||||
use Picqer\Barcode\Types\TypeCode39;
|
||||
use Picqer\Barcode\Types\TypeCode39Checksum;
|
||||
use Picqer\Barcode\Types\TypeCode39Extended;
|
||||
|
||||
class TypesTest extends TestCase
|
||||
{
|
||||
public function test_generator_can_generate_code_39_barcode()
|
||||
{
|
||||
$barcode = (new TypeCode39())->getBarcode('1234567890ABC');
|
||||
$renderer = new SvgRenderer();
|
||||
$result = $renderer->render($barcode, $barcode->getWidth() * 2);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/TypeCode39-1234567890ABC.svg', $result);
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_code_39_checksum_barcode()
|
||||
{
|
||||
$barcode = (new TypeCode39Checksum())->getBarcode('1234567890ABC');
|
||||
$renderer = new SvgRenderer();
|
||||
$result = $renderer->render($barcode, $barcode->getWidth() * 2);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_code_39_extended_barcode()
|
||||
{
|
||||
$barcode = (new TypeCode39Extended())->getBarcode('1234567890abcABC');
|
||||
$renderer = new SvgRenderer();
|
||||
$result = $renderer->render($barcode, $barcode->getWidth() * 2);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/TypeCode39Extended-1234567890abcABC.svg', $result);
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_code_39_extended_checksum_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('1234567890abcABC', $generator::TYPE_CODE_39E_CHECKSUM);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_code_93_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('1234567890abcABC', $generator::TYPE_CODE_93);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_standard_2_5_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('1234567890', $generator::TYPE_STANDARD_2_5);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_standard_2_5_checksum_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('1234567890', $generator::TYPE_STANDARD_2_5_CHECKSUM);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_interleaved_2_5_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('1234567890', $generator::TYPE_INTERLEAVED_2_5);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_interleaved_2_5_checksum_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('1234567890', $generator::TYPE_INTERLEAVED_2_5_CHECKSUM);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_code_128_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('1234567890abcABC-283*33', $generator::TYPE_CODE_128);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/TypeCode128-1234567890abcABC-283-33.svg', $result);
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_code_128_a_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('1234567890', $generator::TYPE_CODE_128_A);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/TypeCode128A-1234567890.svg', $result);
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_code_128_b_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('1234567890abcABC-283*33', $generator::TYPE_CODE_128_B);
|
||||
|
||||
$this->assertStringEqualsFile('tests/verified-files/TypeCode128B-1234567890abcABC-283-33.svg', $result);
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_ean_2_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('22', $generator::TYPE_EAN_2);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_ean_5_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('1234567890abcABC-283*33', $generator::TYPE_EAN_5);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_ean_8_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('1234568', $generator::TYPE_EAN_8);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_ean_13_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('1234567890', $generator::TYPE_EAN_13);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_upc_a_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('123456789', $generator::TYPE_UPC_A);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_upc_e_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('123456789', $generator::TYPE_UPC_E);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_msi_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('123456789', $generator::TYPE_MSI);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_msi_checksum_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('123456789', $generator::TYPE_MSI_CHECKSUM);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_postnet_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('123456789', $generator::TYPE_POSTNET);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_planet_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('123456789', $generator::TYPE_PLANET);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_rms4cc_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('123456789', $generator::TYPE_RMS4CC);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_kix_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('123456789', $generator::TYPE_KIX);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_imb_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('123456789', $generator::TYPE_IMB);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_codabar_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('123456789', $generator::TYPE_CODABAR);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_code_11_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('123456789', $generator::TYPE_CODE_11);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_pharma_code_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('123456789', $generator::TYPE_PHARMA_CODE);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_pharma_code_2_tracks_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('123456789', $generator::TYPE_PHARMA_CODE_TWO_TRACKS);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_telepen_alpha_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('1234567890ASCD', $generator::TYPE_TELEPEN_ALPHA);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
|
||||
public function test_generator_can_generate_telepen_numeric_barcode()
|
||||
{
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode('1234567890', $generator::TYPE_TELEPEN_NUMERIC);
|
||||
|
||||
$this->assertGreaterThan(100, strlen($result));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Picqer\Barcode\Helpers\StringHelpers;
|
||||
|
||||
/*
|
||||
* Test all supported barcodes types, with as much different but supported input strings.
|
||||
* Verified files can be built with generate-verified-files.php file.
|
||||
* Only run that file if you added new types or new strings to test.
|
||||
*
|
||||
* We use SVG because that output is vector and should be the same on every host system.
|
||||
*/
|
||||
|
||||
class VerifiedBarcodeTest extends TestCase
|
||||
{
|
||||
public static array $supportedBarcodes = [
|
||||
['type' => \Picqer\Barcode\Types\TypeCode39::class, 'barcodes' => ['1234567890ABC']],
|
||||
['type' => \Picqer\Barcode\Types\TypeCode39Checksum::class, 'barcodes' => ['1234567890ABC']],
|
||||
['type' => \Picqer\Barcode\Types\TypeCode39Extended::class, 'barcodes' => ['1234567890abcABC']],
|
||||
['type' => \Picqer\Barcode\Types\TypeCode39ExtendedChecksum::class, 'barcodes' => ['1234567890abcABC']],
|
||||
['type' => \Picqer\Barcode\Types\TypeCode93::class, 'barcodes' => ['1234567890abcABC']],
|
||||
['type' => \Picqer\Barcode\Types\TypeStandard2of5::class, 'barcodes' => ['1234567890']],
|
||||
['type' => \Picqer\Barcode\Types\TypeStandard2of5Checksum::class, 'barcodes' => ['1234567890']],
|
||||
['type' => \Picqer\Barcode\Types\TypeInterleaved25::class, 'barcodes' => ['1234567890']],
|
||||
['type' => \Picqer\Barcode\Types\TypeInterleaved25Checksum::class, 'barcodes' => ['1234567890']],
|
||||
['type' => \Picqer\Barcode\Types\TypeEan13::class, 'barcodes' => ['081231723897', '0049000004632', '004900000463']],
|
||||
['type' => \Picqer\Barcode\Types\TypeITF14::class, 'barcodes' => ['00012345600012', '05400141288766']],
|
||||
['type' => \Picqer\Barcode\Types\TypeCode128::class, 'barcodes' => ['081231723897', '1234567890abcABC-283*33']],
|
||||
['type' => \Picqer\Barcode\Types\TypeCode128A::class, 'barcodes' => ['1234567890']],
|
||||
['type' => \Picqer\Barcode\Types\TypeCode128B::class, 'barcodes' => ['081231723897', '1234567890abcABC-283*33']],
|
||||
['type' => \Picqer\Barcode\Types\TypeUpcExtension2::class, 'barcodes' => ['22']],
|
||||
['type' => \Picqer\Barcode\Types\TypeUpcExtension5::class, 'barcodes' => ['1234567890abcABC-283*33']],
|
||||
['type' => \Picqer\Barcode\Types\TypeEan8::class, 'barcodes' => ['1234568']],
|
||||
['type' => \Picqer\Barcode\Types\TypeUpcA::class, 'barcodes' => ['123456789']],
|
||||
['type' => \Picqer\Barcode\Types\TypeUpcE::class, 'barcodes' => ['123456789']],
|
||||
['type' => \Picqer\Barcode\Types\TypeMsi::class, 'barcodes' => ['123456789']],
|
||||
['type' => \Picqer\Barcode\Types\TypeMsiChecksum::class, 'barcodes' => ['123456789']],
|
||||
['type' => \Picqer\Barcode\Types\TypePostnet::class, 'barcodes' => ['123456789']],
|
||||
['type' => \Picqer\Barcode\Types\TypePlanet::class, 'barcodes' => ['123456789']],
|
||||
['type' => \Picqer\Barcode\Types\TypeRms4cc::class, 'barcodes' => ['123456789']],
|
||||
['type' => \Picqer\Barcode\Types\TypeKix::class, 'barcodes' => ['123456789']],
|
||||
['type' => \Picqer\Barcode\Types\TypeIntelligentMailBarcode::class, 'barcodes' => ['123456789']],
|
||||
['type' => \Picqer\Barcode\Types\TypeCodabar::class, 'barcodes' => ['123456789']],
|
||||
['type' => \Picqer\Barcode\Types\TypeCode11::class, 'barcodes' => ['123456789']],
|
||||
['type' => \Picqer\Barcode\Types\TypePharmacode::class, 'barcodes' => ['123456789']],
|
||||
['type' => \Picqer\Barcode\Types\TypePharmacodeTwoCode::class, 'barcodes' => ['123456789']],
|
||||
['type' => \Picqer\Barcode\Types\TypeTelepen::class, 'barcodes' => ['1234567890ASCD']],
|
||||
['type' => \Picqer\Barcode\Types\TypeTelepenNumeric::class, 'barcodes' => ['1234567890']]
|
||||
];
|
||||
|
||||
public function testAllSupportedBarcodeTypes()
|
||||
{
|
||||
$renderer = new Picqer\Barcode\Renderers\SvgRenderer();
|
||||
|
||||
foreach ($this::$supportedBarcodes as $barcodeTestSet) {
|
||||
foreach ($barcodeTestSet['barcodes'] as $barcodeText) {
|
||||
$barcode = (new $barcodeTestSet['type']())->getBarcode($barcodeText);
|
||||
$result = $renderer->render($barcode, $barcode->getWidth() * 2);
|
||||
|
||||
$this->assertStringEqualsFile(
|
||||
sprintf('tests/verified-files/%s.svg', StringHelpers::getSafeFilenameFrom($barcodeTestSet['type'] . '-' . $barcodeText)),
|
||||
$result,
|
||||
sprintf('%s x %s dynamic test failed', $barcodeTestSet['type'], $barcodeText)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" standalone="no" ?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg width="190" height="30" viewBox="0 0 190 30" version="1.1" xmlns="http://www.w3.org/2000/svg">
|
||||
<desc>0049000004632</desc>
|
||||
<g id="bars" fill="rgb(0,0,0)" stroke="none">
|
||||
<rect x="0" y="0" width="2" height="30" />
|
||||
<rect x="4" y="0" width="2" height="30" />
|
||||
<rect x="12" y="0" width="4" height="30" />
|
||||
<rect x="18" y="0" width="2" height="30" />
|
||||
<rect x="22" y="0" width="2" height="30" />
|
||||
<rect x="30" y="0" width="4" height="30" />
|
||||
<rect x="40" y="0" width="2" height="30" />
|
||||
<rect x="44" y="0" width="4" height="30" />
|
||||
<rect x="54" y="0" width="4" height="30" />
|
||||
<rect x="60" y="0" width="2" height="30" />
|
||||
<rect x="68" y="0" width="4" height="30" />
|
||||
<rect x="74" y="0" width="2" height="30" />
|
||||
<rect x="82" y="0" width="4" height="30" />
|
||||
<rect x="88" y="0" width="2" height="30" />
|
||||
<rect x="92" y="0" width="2" height="30" />
|
||||
<rect x="96" y="0" width="2" height="30" />
|
||||
<rect x="100" y="0" width="6" height="30" />
|
||||
<rect x="110" y="0" width="2" height="30" />
|
||||
<rect x="114" y="0" width="6" height="30" />
|
||||
<rect x="124" y="0" width="2" height="30" />
|
||||
<rect x="128" y="0" width="2" height="30" />
|
||||
<rect x="132" y="0" width="6" height="30" />
|
||||
<rect x="142" y="0" width="2" height="30" />
|
||||
<rect x="146" y="0" width="2" height="30" />
|
||||
<rect x="156" y="0" width="2" height="30" />
|
||||
<rect x="166" y="0" width="2" height="30" />
|
||||
<rect x="170" y="0" width="4" height="30" />
|
||||
<rect x="176" y="0" width="4" height="30" />
|
||||
<rect x="184" y="0" width="2" height="30" />
|
||||
<rect x="188" y="0" width="2" height="30" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.7 KiB |
@@ -0,0 +1,30 @@
|
||||
<div style="font-size:0;position:relative;width:202px;height:30px;background-color:rgb(255,0,0);">
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:0px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:6px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:6px;height:30px;position:absolute;left:12px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:22px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:30px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:38px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:44px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:48px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:6px;height:30px;position:absolute;left:56px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:66px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:72px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:82px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:88px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:94px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:106px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:110px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:118px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:128px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:8px;height:30px;position:absolute;left:132px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:142px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:146px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:6px;height:30px;position:absolute;left:154px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:162px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:166px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:176px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:6px;height:30px;position:absolute;left:186px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:194px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:198px;top:0"> </div>
|
||||
</div>
|
||||
@@ -0,0 +1,30 @@
|
||||
<div style="font-size:0;position:relative;width:202px;height:30px;">
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:0px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:6px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:6px;height:30px;position:absolute;left:12px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:22px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:30px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:38px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:44px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:48px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:6px;height:30px;position:absolute;left:56px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:66px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:72px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:82px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:88px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:94px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:106px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:110px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:118px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:128px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:8px;height:30px;position:absolute;left:132px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:142px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:146px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:6px;height:30px;position:absolute;left:154px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:162px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:166px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:176px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:6px;height:30px;position:absolute;left:186px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:194px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:4px;height:30px;position:absolute;left:198px;top:0"> </div>
|
||||
</div>
|
||||
@@ -0,0 +1,30 @@
|
||||
<div style="font-size:0;position:relative;width:100%;height:100%">
|
||||
<div style="background-color:rgb(0,0,0);width:1.980198%;height:100%;position:absolute;left:0%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.990099%;height:100%;position:absolute;left:2.970297%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2.970297%;height:100%;position:absolute;left:5.940594%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.990099%;height:100%;position:absolute;left:10.891089%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:1.980198%;height:100%;position:absolute;left:14.851485%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.990099%;height:100%;position:absolute;left:18.811881%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.990099%;height:100%;position:absolute;left:21.782178%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:1.980198%;height:100%;position:absolute;left:23.762376%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2.970297%;height:100%;position:absolute;left:27.722772%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:1.980198%;height:100%;position:absolute;left:32.673267%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:1.980198%;height:100%;position:absolute;left:35.643564%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:1.980198%;height:100%;position:absolute;left:40.594059%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.990099%;height:100%;position:absolute;left:43.564356%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:1.980198%;height:100%;position:absolute;left:46.534653%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.990099%;height:100%;position:absolute;left:52.475248%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.990099%;height:100%;position:absolute;left:54.455446%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:1.980198%;height:100%;position:absolute;left:58.415842%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.990099%;height:100%;position:absolute;left:63.366337%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:3.960396%;height:100%;position:absolute;left:65.346535%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.990099%;height:100%;position:absolute;left:70.29703%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.990099%;height:100%;position:absolute;left:72.277228%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2.970297%;height:100%;position:absolute;left:76.237624%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.990099%;height:100%;position:absolute;left:80.19802%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:1.980198%;height:100%;position:absolute;left:82.178218%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:1.980198%;height:100%;position:absolute;left:87.128713%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2.970297%;height:100%;position:absolute;left:92.079208%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.990099%;height:100%;position:absolute;left:96.039604%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:1.980198%;height:100%;position:absolute;left:98.019802%;top:0"> </div>
|
||||
</div>
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" standalone="no" ?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg width="23.75" height="25.75" viewBox="0 0 23.75 25.75" version="1.1" xmlns="http://www.w3.org/2000/svg">
|
||||
<desc>0812317238973</desc>
|
||||
<g id="bars" fill="rgb(0,0,0)" stroke="none">
|
||||
<rect x="0" y="0" width="0.25" height="25.75" />
|
||||
<rect x="0.5" y="0" width="0.25" height="25.75" />
|
||||
<rect x="1" y="0" width="0.5" height="25.75" />
|
||||
<rect x="1.75" y="0" width="0.75" height="25.75" />
|
||||
<rect x="3" y="0" width="0.5" height="25.75" />
|
||||
<rect x="4" y="0" width="0.25" height="25.75" />
|
||||
<rect x="4.75" y="0" width="0.25" height="25.75" />
|
||||
<rect x="5.5" y="0" width="0.5" height="25.75" />
|
||||
<rect x="6.25" y="0" width="1" height="25.75" />
|
||||
<rect x="7.5" y="0" width="0.25" height="25.75" />
|
||||
<rect x="8.25" y="0" width="0.5" height="25.75" />
|
||||
<rect x="9.25" y="0" width="0.25" height="25.75" />
|
||||
<rect x="9.75" y="0" width="0.75" height="25.75" />
|
||||
<rect x="10.75" y="0" width="0.5" height="25.75" />
|
||||
<rect x="11.5" y="0" width="0.25" height="25.75" />
|
||||
<rect x="12" y="0" width="0.25" height="25.75" />
|
||||
<rect x="12.5" y="0" width="0.5" height="25.75" />
|
||||
<rect x="13.25" y="0" width="0.5" height="25.75" />
|
||||
<rect x="14.25" y="0" width="0.25" height="25.75" />
|
||||
<rect x="15.5" y="0" width="0.25" height="25.75" />
|
||||
<rect x="16" y="0" width="0.25" height="25.75" />
|
||||
<rect x="16.75" y="0" width="0.25" height="25.75" />
|
||||
<rect x="17.75" y="0" width="0.75" height="25.75" />
|
||||
<rect x="18.75" y="0" width="0.25" height="25.75" />
|
||||
<rect x="19.5" y="0" width="0.25" height="25.75" />
|
||||
<rect x="20.5" y="0" width="0.25" height="25.75" />
|
||||
<rect x="21.25" y="0" width="0.25" height="25.75" />
|
||||
<rect x="22.5" y="0" width="0.25" height="25.75" />
|
||||
<rect x="23" y="0" width="0.25" height="25.75" />
|
||||
<rect x="23.5" y="0" width="0.25" height="25.75" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.9 KiB |
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" standalone="no" ?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg width="190" height="30" viewBox="0 0 190 30" version="1.1" xmlns="http://www.w3.org/2000/svg">
|
||||
<desc>0812317238973</desc>
|
||||
<rect id="background" width="100%" height="100%" fill="rgb(255,0,0)"/>
|
||||
<g id="bars" fill="rgb(0,0,0)" stroke="none">
|
||||
<rect x="0" y="0" width="2" height="30" />
|
||||
<rect x="4" y="0" width="2" height="30" />
|
||||
<rect x="8" y="0" width="4" height="30" />
|
||||
<rect x="14" y="0" width="6" height="30" />
|
||||
<rect x="24" y="0" width="4" height="30" />
|
||||
<rect x="32" y="0" width="2" height="30" />
|
||||
<rect x="38" y="0" width="2" height="30" />
|
||||
<rect x="44" y="0" width="4" height="30" />
|
||||
<rect x="50" y="0" width="8" height="30" />
|
||||
<rect x="60" y="0" width="2" height="30" />
|
||||
<rect x="66" y="0" width="4" height="30" />
|
||||
<rect x="74" y="0" width="2" height="30" />
|
||||
<rect x="78" y="0" width="6" height="30" />
|
||||
<rect x="86" y="0" width="4" height="30" />
|
||||
<rect x="92" y="0" width="2" height="30" />
|
||||
<rect x="96" y="0" width="2" height="30" />
|
||||
<rect x="100" y="0" width="4" height="30" />
|
||||
<rect x="106" y="0" width="4" height="30" />
|
||||
<rect x="114" y="0" width="2" height="30" />
|
||||
<rect x="124" y="0" width="2" height="30" />
|
||||
<rect x="128" y="0" width="2" height="30" />
|
||||
<rect x="134" y="0" width="2" height="30" />
|
||||
<rect x="142" y="0" width="6" height="30" />
|
||||
<rect x="150" y="0" width="2" height="30" />
|
||||
<rect x="156" y="0" width="2" height="30" />
|
||||
<rect x="164" y="0" width="2" height="30" />
|
||||
<rect x="170" y="0" width="2" height="30" />
|
||||
<rect x="180" y="0" width="2" height="30" />
|
||||
<rect x="184" y="0" width="2" height="30" />
|
||||
<rect x="188" y="0" width="2" height="30" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.7 KiB |
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" standalone="no" ?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg width="190" height="30" viewBox="0 0 190 30" version="1.1" xmlns="http://www.w3.org/2000/svg">
|
||||
<desc>0812317238973</desc>
|
||||
<g id="bars" fill="rgb(0,0,0)" stroke="none">
|
||||
<rect x="0" y="0" width="2" height="30" />
|
||||
<rect x="4" y="0" width="2" height="30" />
|
||||
<rect x="8" y="0" width="4" height="30" />
|
||||
<rect x="14" y="0" width="6" height="30" />
|
||||
<rect x="24" y="0" width="4" height="30" />
|
||||
<rect x="32" y="0" width="2" height="30" />
|
||||
<rect x="38" y="0" width="2" height="30" />
|
||||
<rect x="44" y="0" width="4" height="30" />
|
||||
<rect x="50" y="0" width="8" height="30" />
|
||||
<rect x="60" y="0" width="2" height="30" />
|
||||
<rect x="66" y="0" width="4" height="30" />
|
||||
<rect x="74" y="0" width="2" height="30" />
|
||||
<rect x="78" y="0" width="6" height="30" />
|
||||
<rect x="86" y="0" width="4" height="30" />
|
||||
<rect x="92" y="0" width="2" height="30" />
|
||||
<rect x="96" y="0" width="2" height="30" />
|
||||
<rect x="100" y="0" width="4" height="30" />
|
||||
<rect x="106" y="0" width="4" height="30" />
|
||||
<rect x="114" y="0" width="2" height="30" />
|
||||
<rect x="124" y="0" width="2" height="30" />
|
||||
<rect x="128" y="0" width="2" height="30" />
|
||||
<rect x="134" y="0" width="2" height="30" />
|
||||
<rect x="142" y="0" width="6" height="30" />
|
||||
<rect x="150" y="0" width="2" height="30" />
|
||||
<rect x="156" y="0" width="2" height="30" />
|
||||
<rect x="164" y="0" width="2" height="30" />
|
||||
<rect x="170" y="0" width="2" height="30" />
|
||||
<rect x="180" y="0" width="2" height="30" />
|
||||
<rect x="184" y="0" width="2" height="30" />
|
||||
<rect x="188" y="0" width="2" height="30" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.7 KiB |
@@ -0,0 +1,67 @@
|
||||
<div style="font-size:0;position:relative;width:100%;height:100%">
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:0%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:33.333%;position:absolute;left:1.550388%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:3.100775%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:4.651163%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:33.333%;position:absolute;left:6.20155%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:33.333%;position:absolute;left:7.751938%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:9.302326%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:33.333%;position:absolute;left:10.852713%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:12.403101%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:100%;position:absolute;left:13.953488%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:15.503876%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:100%;position:absolute;left:17.054264%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:100%;position:absolute;left:18.604651%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:100%;position:absolute;left:20.155039%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:100%;position:absolute;left:21.705426%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:23.255814%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:24.806202%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:100%;position:absolute;left:26.356589%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:27.906977%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:29.457364%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:100%;position:absolute;left:31.007752%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:32.55814%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:34.108527%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:35.658915%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:100%;position:absolute;left:37.209302%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:38.75969%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:33.333%;position:absolute;left:40.310078%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:41.860465%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:100%;position:absolute;left:43.410853%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:33.333%;position:absolute;left:44.96124%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:46.511628%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:48.062016%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:33.333%;position:absolute;left:49.612403%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:100%;position:absolute;left:51.162791%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:33.333%;position:absolute;left:52.713178%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:33.333%;position:absolute;left:54.263566%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:55.813953%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:100%;position:absolute;left:57.364341%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:58.914729%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:33.333%;position:absolute;left:60.465116%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:62.015504%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:100%;position:absolute;left:63.565891%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:33.333%;position:absolute;left:65.116279%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:66.666667%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:68.217054%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:69.767442%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:33.333%;position:absolute;left:71.317829%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:33.333%;position:absolute;left:72.868217%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:33.333%;position:absolute;left:74.418605%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:33.333%;position:absolute;left:75.968992%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:100%;position:absolute;left:77.51938%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:33.333%;position:absolute;left:79.069767%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:80.620155%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:82.170543%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:83.72093%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:85.271318%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:33.333%;position:absolute;left:86.821705%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:88.372093%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:89.922481%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:100%;position:absolute;left:91.472868%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:100%;position:absolute;left:93.023256%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:94.573643%;top:33.333%"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:100%;position:absolute;left:96.124031%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:100%;position:absolute;left:97.674419%;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:0.775194%;height:66.667%;position:absolute;left:99.224806%;top:33.333%"> </div>
|
||||
</div>
|
||||
@@ -0,0 +1,67 @@
|
||||
<div style="font-size:0;position:relative;width:258px;height:30px;">
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:0px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:10px;position:absolute;left:4px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:8px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:12px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:10px;position:absolute;left:16px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:10px;position:absolute;left:20px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:24px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:10px;position:absolute;left:28px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:32px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:36px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:40px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:44px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:48px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:52px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:56px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:60px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:64px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:68px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:72px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:76px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:80px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:84px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:88px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:92px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:96px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:100px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:10px;position:absolute;left:104px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:108px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:112px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:10px;position:absolute;left:116px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:120px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:124px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:10px;position:absolute;left:128px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:132px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:10px;position:absolute;left:136px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:10px;position:absolute;left:140px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:144px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:148px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:152px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:10px;position:absolute;left:156px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:160px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:164px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:10px;position:absolute;left:168px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:172px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:176px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:180px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:10px;position:absolute;left:184px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:10px;position:absolute;left:188px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:10px;position:absolute;left:192px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:10px;position:absolute;left:196px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:200px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:10px;position:absolute;left:204px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:208px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:212px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:216px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:220px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:10px;position:absolute;left:224px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:228px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:232px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:236px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:240px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:244px;top:10px"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:248px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:30px;position:absolute;left:252px;top:0"> </div>
|
||||
<div style="background-color:rgb(0,0,0);width:2px;height:20px;position:absolute;left:256px;top:10px"> </div>
|
||||
</div>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" standalone="no" ?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg width="224" height="30" viewBox="0 0 224 30" version="1.1" xmlns="http://www.w3.org/2000/svg">
|
||||
<desc>123456789</desc>
|
||||
<g id="bars" fill="rgb(0,0,0)" stroke="none">
|
||||
<rect x="0" y="0" width="2" height="30" />
|
||||
<rect x="4" y="0" width="4" height="30" />
|
||||
<rect x="12" y="0" width="2" height="30" />
|
||||
<rect x="18" y="0" width="2" height="30" />
|
||||
<rect x="22" y="0" width="2" height="30" />
|
||||
<rect x="26" y="0" width="2" height="30" />
|
||||
<rect x="30" y="0" width="4" height="30" />
|
||||
<rect x="38" y="0" width="2" height="30" />
|
||||
<rect x="42" y="0" width="2" height="30" />
|
||||
<rect x="46" y="0" width="2" height="30" />
|
||||
<rect x="52" y="0" width="2" height="30" />
|
||||
<rect x="56" y="0" width="4" height="30" />
|
||||
<rect x="62" y="0" width="4" height="30" />
|
||||
<rect x="70" y="0" width="2" height="30" />
|
||||
<rect x="74" y="0" width="2" height="30" />
|
||||
<rect x="78" y="0" width="2" height="30" />
|
||||
<rect x="82" y="0" width="2" height="30" />
|
||||
<rect x="86" y="0" width="4" height="30" />
|
||||
<rect x="92" y="0" width="2" height="30" />
|
||||
<rect x="98" y="0" width="2" height="30" />
|
||||
<rect x="102" y="0" width="4" height="30" />
|
||||
<rect x="108" y="0" width="2" height="30" />
|
||||
<rect x="112" y="0" width="2" height="30" />
|
||||
<rect x="118" y="0" width="2" height="30" />
|
||||
<rect x="122" y="0" width="2" height="30" />
|
||||
<rect x="128" y="0" width="2" height="30" />
|
||||
<rect x="132" y="0" width="2" height="30" />
|
||||
<rect x="136" y="0" width="4" height="30" />
|
||||
<rect x="142" y="0" width="2" height="30" />
|
||||
<rect x="148" y="0" width="2" height="30" />
|
||||
<rect x="152" y="0" width="4" height="30" />
|
||||
<rect x="158" y="0" width="2" height="30" />
|
||||
<rect x="162" y="0" width="2" height="30" />
|
||||
<rect x="168" y="0" width="4" height="30" />
|
||||
<rect x="174" y="0" width="2" height="30" />
|
||||
<rect x="178" y="0" width="2" height="30" />
|
||||
<rect x="182" y="0" width="4" height="30" />
|
||||
<rect x="188" y="0" width="2" height="30" />
|
||||
<rect x="194" y="0" width="2" height="30" />
|
||||
<rect x="198" y="0" width="2" height="30" />
|
||||
<rect x="202" y="0" width="2" height="30" />
|
||||
<rect x="206" y="0" width="4" height="30" />
|
||||
<rect x="214" y="0" width="2" height="30" />
|
||||
<rect x="220" y="0" width="2" height="30" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.3 KiB |
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" standalone="no" ?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg width="188" height="30" viewBox="0 0 188 30" version="1.1" xmlns="http://www.w3.org/2000/svg">
|
||||
<desc>123456789</desc>
|
||||
<g id="bars" fill="rgb(0,0,0)" stroke="none">
|
||||
<rect x="0" y="0" width="2" height="30" />
|
||||
<rect x="4" y="0" width="4" height="30" />
|
||||
<rect x="12" y="0" width="2" height="30" />
|
||||
<rect x="16" y="0" width="4" height="30" />
|
||||
<rect x="22" y="0" width="2" height="30" />
|
||||
<rect x="26" y="0" width="4" height="30" />
|
||||
<rect x="32" y="0" width="2" height="30" />
|
||||
<rect x="38" y="0" width="2" height="30" />
|
||||
<rect x="42" y="0" width="4" height="30" />
|
||||
<rect x="48" y="0" width="4" height="30" />
|
||||
<rect x="56" y="0" width="2" height="30" />
|
||||
<rect x="60" y="0" width="2" height="30" />
|
||||
<rect x="64" y="0" width="2" height="30" />
|
||||
<rect x="68" y="0" width="4" height="30" />
|
||||
<rect x="74" y="0" width="4" height="30" />
|
||||
<rect x="80" y="0" width="4" height="30" />
|
||||
<rect x="86" y="0" width="4" height="30" />
|
||||
<rect x="92" y="0" width="2" height="30" />
|
||||
<rect x="96" y="0" width="2" height="30" />
|
||||
<rect x="102" y="0" width="4" height="30" />
|
||||
<rect x="108" y="0" width="2" height="30" />
|
||||
<rect x="112" y="0" width="2" height="30" />
|
||||
<rect x="116" y="0" width="2" height="30" />
|
||||
<rect x="122" y="0" width="4" height="30" />
|
||||
<rect x="128" y="0" width="4" height="30" />
|
||||
<rect x="134" y="0" width="2" height="30" />
|
||||
<rect x="140" y="0" width="2" height="30" />
|
||||
<rect x="144" y="0" width="4" height="30" />
|
||||
<rect x="150" y="0" width="2" height="30" />
|
||||
<rect x="154" y="0" width="2" height="30" />
|
||||
<rect x="158" y="0" width="2" height="30" />
|
||||
<rect x="162" y="0" width="2" height="30" />
|
||||
<rect x="166" y="0" width="4" height="30" />
|
||||
<rect x="172" y="0" width="2" height="30" />
|
||||
<rect x="176" y="0" width="4" height="30" />
|
||||
<rect x="184" y="0" width="2" height="30" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.9 KiB |
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" standalone="no" ?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg width="202" height="30" viewBox="0 0 202 30" version="1.1" xmlns="http://www.w3.org/2000/svg">
|
||||
<desc>081231723897</desc>
|
||||
<g id="bars" fill="rgb(0,0,0)" stroke="none">
|
||||
<rect x="0" y="0" width="4" height="30" />
|
||||
<rect x="6" y="0" width="2" height="30" />
|
||||
<rect x="12" y="0" width="6" height="30" />
|
||||
<rect x="22" y="0" width="2" height="30" />
|
||||
<rect x="30" y="0" width="4" height="30" />
|
||||
<rect x="38" y="0" width="2" height="30" />
|
||||
<rect x="44" y="0" width="2" height="30" />
|
||||
<rect x="48" y="0" width="4" height="30" />
|
||||
<rect x="56" y="0" width="6" height="30" />
|
||||
<rect x="66" y="0" width="4" height="30" />
|
||||
<rect x="72" y="0" width="4" height="30" />
|
||||
<rect x="82" y="0" width="4" height="30" />
|
||||
<rect x="88" y="0" width="2" height="30" />
|
||||
<rect x="94" y="0" width="4" height="30" />
|
||||
<rect x="106" y="0" width="2" height="30" />
|
||||
<rect x="110" y="0" width="2" height="30" />
|
||||
<rect x="118" y="0" width="4" height="30" />
|
||||
<rect x="128" y="0" width="2" height="30" />
|
||||
<rect x="132" y="0" width="8" height="30" />
|
||||
<rect x="142" y="0" width="2" height="30" />
|
||||
<rect x="146" y="0" width="2" height="30" />
|
||||
<rect x="154" y="0" width="6" height="30" />
|
||||
<rect x="162" y="0" width="2" height="30" />
|
||||
<rect x="166" y="0" width="4" height="30" />
|
||||
<rect x="176" y="0" width="4" height="30" />
|
||||
<rect x="186" y="0" width="6" height="30" />
|
||||
<rect x="194" y="0" width="2" height="30" />
|
||||
<rect x="198" y="0" width="4" height="30" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
@@ -0,0 +1,74 @@
|
||||
<?xml version="1.0" standalone="no" ?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg width="488" height="30" viewBox="0 0 488 30" version="1.1" xmlns="http://www.w3.org/2000/svg">
|
||||
<desc>1234567890abcABC-283*33</desc>
|
||||
<g id="bars" fill="rgb(0,0,0)" stroke="none">
|
||||
<rect x="0" y="0" width="4" height="30" />
|
||||
<rect x="6" y="0" width="2" height="30" />
|
||||
<rect x="12" y="0" width="6" height="30" />
|
||||
<rect x="22" y="0" width="2" height="30" />
|
||||
<rect x="26" y="0" width="4" height="30" />
|
||||
<rect x="34" y="0" width="6" height="30" />
|
||||
<rect x="44" y="0" width="2" height="30" />
|
||||
<rect x="52" y="0" width="2" height="30" />
|
||||
<rect x="56" y="0" width="4" height="30" />
|
||||
<rect x="66" y="0" width="6" height="30" />
|
||||
<rect x="78" y="0" width="2" height="30" />
|
||||
<rect x="82" y="0" width="4" height="30" />
|
||||
<rect x="88" y="0" width="4" height="30" />
|
||||
<rect x="100" y="0" width="2" height="30" />
|
||||
<rect x="104" y="0" width="2" height="30" />
|
||||
<rect x="110" y="0" width="4" height="30" />
|
||||
<rect x="116" y="0" width="8" height="30" />
|
||||
<rect x="126" y="0" width="4" height="30" />
|
||||
<rect x="132" y="0" width="2" height="30" />
|
||||
<rect x="136" y="0" width="8" height="30" />
|
||||
<rect x="146" y="0" width="6" height="30" />
|
||||
<rect x="154" y="0" width="2" height="30" />
|
||||
<rect x="160" y="0" width="2" height="30" />
|
||||
<rect x="164" y="0" width="4" height="30" />
|
||||
<rect x="176" y="0" width="2" height="30" />
|
||||
<rect x="182" y="0" width="2" height="30" />
|
||||
<rect x="192" y="0" width="4" height="30" />
|
||||
<rect x="198" y="0" width="2" height="30" />
|
||||
<rect x="208" y="0" width="2" height="30" />
|
||||
<rect x="212" y="0" width="4" height="30" />
|
||||
<rect x="220" y="0" width="2" height="30" />
|
||||
<rect x="224" y="0" width="2" height="30" />
|
||||
<rect x="232" y="0" width="4" height="30" />
|
||||
<rect x="242" y="0" width="2" height="30" />
|
||||
<rect x="250" y="0" width="2" height="30" />
|
||||
<rect x="254" y="0" width="4" height="30" />
|
||||
<rect x="264" y="0" width="2" height="30" />
|
||||
<rect x="272" y="0" width="2" height="30" />
|
||||
<rect x="280" y="0" width="4" height="30" />
|
||||
<rect x="286" y="0" width="2" height="30" />
|
||||
<rect x="292" y="0" width="4" height="30" />
|
||||
<rect x="298" y="0" width="6" height="30" />
|
||||
<rect x="308" y="0" width="4" height="30" />
|
||||
<rect x="316" y="0" width="6" height="30" />
|
||||
<rect x="326" y="0" width="2" height="30" />
|
||||
<rect x="330" y="0" width="6" height="30" />
|
||||
<rect x="338" y="0" width="2" height="30" />
|
||||
<rect x="344" y="0" width="4" height="30" />
|
||||
<rect x="352" y="0" width="4" height="30" />
|
||||
<rect x="360" y="0" width="2" height="30" />
|
||||
<rect x="364" y="0" width="6" height="30" />
|
||||
<rect x="374" y="0" width="4" height="30" />
|
||||
<rect x="382" y="0" width="2" height="30" />
|
||||
<rect x="390" y="0" width="2" height="30" />
|
||||
<rect x="396" y="0" width="4" height="30" />
|
||||
<rect x="404" y="0" width="2" height="30" />
|
||||
<rect x="408" y="0" width="6" height="30" />
|
||||
<rect x="418" y="0" width="4" height="30" />
|
||||
<rect x="426" y="0" width="2" height="30" />
|
||||
<rect x="430" y="0" width="6" height="30" />
|
||||
<rect x="440" y="0" width="2" height="30" />
|
||||
<rect x="444" y="0" width="8" height="30" />
|
||||
<rect x="454" y="0" width="6" height="30" />
|
||||
<rect x="462" y="0" width="4" height="30" />
|
||||
<rect x="472" y="0" width="6" height="30" />
|
||||
<rect x="480" y="0" width="2" height="30" />
|
||||
<rect x="484" y="0" width="4" height="30" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.4 KiB |