Initial import

This commit is contained in:
sas.fajri
2026-05-25 20:01:37 +07:00
commit 710d7c1b97
10371 changed files with 2381698 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
.idea
.DS_Store
vendor
composer.lock

View File

@@ -0,0 +1,12 @@
language: php
php:
- 5.6
- 7.0
- hhvm
sudo: false
install: composer install --no-interaction --prefer-source
script: vendor/bin/phpunit

View File

@@ -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.

View File

@@ -0,0 +1,78 @@
# PHP Barcode Generator [![Build Status](https://travis-ci.org/picqer/php-barcode-generator.svg?branch=master)](https://travis-ci.org/picqer/php-barcode-generator) [![Total Downloads](https://poser.pugx.org/picqer/php-barcode-generator/downloads)](https://packagist.org/packages/picqer/php-barcode-generator)
This is an easy to use, non-bloated, framework independent, barcode generator in PHP.
It creates SVG, PNG, JPG and HTML images, from the most used 1D barcode standards.
*The codebase is largely from the [TCPDF barcode generator](https://github.com/tecnickcom/TCPDF) by Nicola Asuni. This code is therefor licensed under LGPLv3. It is still a bit of a mess, bit I will clean it in the future. I do not expect the interface of this class will change during the clean ups.*
## 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.
## Usage
Initiate the barcode generator for the output you want, then call the ->getBarcode() routine as many times as you want.
```php
$generator = new Picqer\Barcode\BarcodeGeneratorHTML();
echo $generator->getBarcode('081231723897', $generator::TYPE_CODE_128);
```
The ->getBarcode() routine accepts the following:
- $code Data for 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
- $totalHeight The total height of the barcode
- $color Hex code of the foreground color
## Image types
```php
$generatorSVG = new Picqer\Barcode\BarcodeGeneratorSVG();
$generatorPNG = new Picqer\Barcode\BarcodeGeneratorPNG();
$generatorJPG = new Picqer\Barcode\BarcodeGeneratorJPG();
$generatorHTML = new Picqer\Barcode\BarcodeGeneratorHTML();
```
## Accepted types
- 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_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
## Examples
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)) . '">';
```

View File

@@ -0,0 +1,30 @@
{
"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": "http://github.com/picqer/php-barcode-generator",
"license": "LGPLv3",
"authors": [
{
"name": "Nicola Asuni",
"email": "info@tecnick.com",
"homepage": "http://nicolaasuni.tecnick.com"
},
{
"name": "Casper Bakker",
"email": "info@picqer.com"
}
],
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "^5.3"
},
"autoload": {
"psr-4": {
"Picqer\\Barcode\\": "src"
}
}
}

View File

@@ -0,0 +1,16 @@
<?php
include('src/BarcodeGenerator.php');
include('src/BarcodeGeneratorPNG.php');
include('src/BarcodeGeneratorSVG.php');
include('src/BarcodeGeneratorJPG.php');
include('src/BarcodeGeneratorHTML.php');
$generatorSVG = new Picqer\Barcode\BarcodeGeneratorSVG();
file_put_contents('tests/verified-files/081231723897-ean13.svg', $generatorSVG->getBarcode('081231723897', $generatorSVG::TYPE_EAN_13));
$generatorHTML = new Picqer\Barcode\BarcodeGeneratorHTML();
file_put_contents('tests/verified-files/081231723897-code128.html', $generatorHTML->getBarcode('081231723897', $generatorHTML::TYPE_CODE_128));
$generatorSVG = new Picqer\Barcode\BarcodeGeneratorSVG();
file_put_contents('tests/verified-files/0049000004632-ean13.svg', $generatorSVG->getBarcode('0049000004632', $generatorSVG::TYPE_EAN_13));

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
syntaxCheck="true"
verbose="true"
>
<testsuites>
<testsuite name="Barcode Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>
</phpunit>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,43 @@
<?php
namespace Picqer\Barcode;
class BarcodeGeneratorHTML extends BarcodeGenerator
{
/**
* Return an HTML representation of barcode.
*
* @param string $code code to print
* @param string $type type of barcode
* @param int $widthFactor Width of a single bar element in pixels.
* @param int $totalHeight Height of a single bar element in pixels.
* @param int|string $color Foreground color for bar elements (background is transparent).
* @return string HTML code.
* @public
*/
public function getBarcode($code, $type, $widthFactor = 2, $totalHeight = 30, $color = 'black')
{
$barcodeData = $this->getBarcodeData($code, $type);
$html = '<div style="font-size:0;position:relative;width:' . ($barcodeData['maxWidth'] * $widthFactor) . 'px;height:' . ($totalHeight) . 'px;">' . "\n";
$positionHorizontal = 0;
foreach ($barcodeData['bars'] as $bar) {
$barWidth = round(($bar['width'] * $widthFactor), 3);
$barHeight = round(($bar['height'] * $totalHeight / $barcodeData['maxHeight']), 3);
if ($bar['drawBar']) {
$positionVertical = round(($bar['positionVertical'] * $totalHeight / $barcodeData['maxHeight']), 3);
// draw a vertical bar
$html .= '<div style="background-color:' . $color . ';width:' . $barWidth . 'px;height:' . $barHeight . 'px;position:absolute;left:' . $positionHorizontal . 'px;top:' . $positionVertical . 'px;">&nbsp;</div>' . "\n";
}
$positionHorizontal += $barWidth;
}
$html .= '</div>' . "\n";
return $html;
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace Picqer\Barcode;
use Picqer\Barcode\Exceptions\BarcodeException;
class BarcodeGeneratorJPG extends BarcodeGenerator
{
/**
* Return a JPG image representation of barcode (requires GD or Imagick library).
*
* @param string $code code to print
* @param string $type type of barcode:
* @param int $widthFactor Width of a single bar element in pixels.
* @param int $totalHeight Height of a single bar element in pixels.
* @param array $color RGB (0-255) foreground color for bar elements (background is transparent).
* @return string image data or false in case of error.
* @public
* @throws BarcodeException
*/
public function getBarcode($code, $type, $widthFactor = 2, $totalHeight = 30, $color = array(0, 0, 0))
{
$barcodeData = $this->getBarcodeData($code, $type);
// calculate image size
$width = ($barcodeData['maxWidth'] * $widthFactor);
$height = $totalHeight;
if (function_exists('imagecreate')) {
// GD library
$imagick = false;
$jpg = imagecreate($width, $height);
$colorBackground = imagecolorallocate($jpg, 255, 255, 255);
imagecolortransparent($jpg, $colorBackground);
$colorForeground = imagecolorallocate($jpg, $color[0], $color[1], $color[2]);
} elseif (extension_loaded('imagick')) {
$imagick = true;
$colorForeground = new \imagickpixel('rgb(' . $color[0] . ',' . $color[1] . ',' . $color[2] . ')');
$jpg = new \Imagick();
$jpg->newImage($width, $height, 'white', 'jpg');
$imageMagickObject = new \imagickdraw();
$imageMagickObject->setFillColor($colorForeground);
} else {
throw new BarcodeException('Neither gd-lib or imagick are installed!');
}
// print bars
$positionHorizontal = 0;
foreach ($barcodeData['bars'] as $bar) {
$bw = round(($bar['width'] * $widthFactor), 3);
$bh = round(($bar['height'] * $totalHeight / $barcodeData['maxHeight']), 3);
if ($bar['drawBar']) {
$y = round(($bar['positionVertical'] * $totalHeight / $barcodeData['maxHeight']), 3);
// draw a vertical bar
if ($imagick && isset($imageMagickObject)) {
$imageMagickObject->rectangle($positionHorizontal, $y, ($positionHorizontal + $bw), ($y + $bh));
} else {
imagefilledrectangle($jpg, $positionHorizontal, $y, ($positionHorizontal + $bw) - 1, ($y + $bh),
$colorForeground);
}
}
$positionHorizontal += $bw;
}
ob_start();
if ($imagick && isset($imageMagickObject)) {
$jpg->drawImage($imageMagickObject);
echo $jpg;
} else {
imagejpeg($jpg);
imagedestroy($jpg);
}
$image = ob_get_clean();
return $image;
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace Picqer\Barcode;
use Picqer\Barcode\Exceptions\BarcodeException;
class BarcodeGeneratorPNG extends BarcodeGenerator
{
/**
* Return a PNG image representation of barcode (requires GD or Imagick library).
*
* @param string $code code to print
* @param string $type type of barcode:
* @param int $widthFactor Width of a single bar element in pixels.
* @param int $totalHeight Height of a single bar element in pixels.
* @param array $color RGB (0-255) foreground color for bar elements (background is transparent).
* @return string image data or false in case of error.
* @public
*/
public function getBarcode($code, $type, $widthFactor = 2, $totalHeight = 30, $color = array(0, 0, 0))
{
$barcodeData = $this->getBarcodeData($code, $type);
// calculate image size
$width = ($barcodeData['maxWidth'] * $widthFactor);
$height = $totalHeight;
if (function_exists('imagecreate')) {
// GD library
$imagick = false;
$png = imagecreate($width, $height);
$colorBackground = imagecolorallocate($png, 255, 255, 255);
imagecolortransparent($png, $colorBackground);
$colorForeground = imagecolorallocate($png, $color[0], $color[1], $color[2]);
} elseif (extension_loaded('imagick')) {
$imagick = true;
$colorForeground = new \imagickpixel('rgb(' . $color[0] . ',' . $color[1] . ',' . $color[2] . ')');
$png = new \Imagick();
$png->newImage($width, $height, 'none', 'png');
$imageMagickObject = new \imagickdraw();
$imageMagickObject->setFillColor($colorForeground);
} else {
throw new BarcodeException('Neither gd-lib or imagick are installed!');
}
// print bars
$positionHorizontal = 0;
foreach ($barcodeData['bars'] as $bar) {
$bw = round(($bar['width'] * $widthFactor), 3);
$bh = round(($bar['height'] * $totalHeight / $barcodeData['maxHeight']), 3);
if ($bar['drawBar']) {
$y = round(($bar['positionVertical'] * $totalHeight / $barcodeData['maxHeight']), 3);
// draw a vertical bar
if ($imagick && isset($imageMagickObject)) {
$imageMagickObject->rectangle($positionHorizontal, $y, ($positionHorizontal + $bw), ($y + $bh));
} else {
imagefilledrectangle($png, $positionHorizontal, $y, ($positionHorizontal + $bw) - 1, ($y + $bh),
$colorForeground);
}
}
$positionHorizontal += $bw;
}
ob_start();
if ($imagick && isset($imageMagickObject)) {
$png->drawImage($imageMagickObject);
echo $png;
} else {
imagepng($png);
imagedestroy($png);
}
$image = ob_get_clean();
return $image;
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace Picqer\Barcode;
class BarcodeGeneratorSVG extends BarcodeGenerator
{
/**
* Return a SVG string representation of barcode.
*
* @param $code (string) code to print
* @param $type (const) type of barcode
* @param $widthFactor (int) Minimum width of a single bar in user units.
* @param $totalHeight (int) Height of barcode in user units.
* @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent).
* @return string SVG code.
* @public
*/
public function getBarcode($code, $type, $widthFactor = 2, $totalHeight = 30, $color = 'black')
{
$barcodeData = $this->getBarcodeData($code, $type);
// replace table for special characters
$repstr = array("\0" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;');
$width = round(($barcodeData['maxWidth'] * $widthFactor), 3);
$svg = '<?xml version="1.0" standalone="no" ?>' . "\n";
$svg .= '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' . "\n";
$svg .= '<svg width="' . $width . '" height="' . $totalHeight . '" viewBox="0 0 ' . $width . ' ' . $totalHeight . '" version="1.1" xmlns="http://www.w3.org/2000/svg">' . "\n";
$svg .= "\t" . '<desc>' . strtr($barcodeData['code'], $repstr) . '</desc>' . "\n";
$svg .= "\t" . '<g id="bars" fill="' . $color . '" stroke="none">' . "\n";
// print bars
$positionHorizontal = 0;
foreach ($barcodeData['bars'] as $bar) {
$barWidth = round(($bar['width'] * $widthFactor), 3);
$barHeight = round(($bar['height'] * $totalHeight / $barcodeData['maxHeight']), 3);
if ($bar['drawBar']) {
$positionVertical = round(($bar['positionVertical'] * $totalHeight / $barcodeData['maxHeight']), 3);
// draw a vertical bar
$svg .= "\t\t" . '<rect x="' . $positionHorizontal . '" y="' . $positionVertical . '" width="' . $barWidth . '" height="' . $barHeight . '" />' . "\n";
}
$positionHorizontal += $barWidth;
}
$svg .= "\t" . '</g>' . "\n";
$svg .= '</svg>' . "\n";
return $svg;
}
}

View File

@@ -0,0 +1,5 @@
<?php
namespace Picqer\Barcode\Exceptions;
class BarcodeException extends \Exception {}

View File

@@ -0,0 +1,5 @@
<?php
namespace Picqer\Barcode\Exceptions;
class InvalidCharacterException extends BarcodeException {}

View File

@@ -0,0 +1,5 @@
<?php
namespace Picqer\Barcode\Exceptions;
class InvalidCheckDigitException extends BarcodeException {}

View File

@@ -0,0 +1,5 @@
<?php
namespace Picqer\Barcode\Exceptions;
class InvalidFormatException extends BarcodeException {}

View File

@@ -0,0 +1,5 @@
<?php
namespace Picqer\Barcode\Exceptions;
class InvalidLengthException extends BarcodeException {}

View File

@@ -0,0 +1,5 @@
<?php
namespace Picqer\Barcode\Exceptions;
class UnknownTypeException extends BarcodeException {}

View File

@@ -0,0 +1,109 @@
<?php
class BarcodeTest extends PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function png_barcode_generator_can_generate_code_128_barcode()
{
$generator = new Picqer\Barcode\BarcodeGeneratorPNG();
$generated = $generator->getBarcode('081231723897', $generator::TYPE_CODE_128);
$this->assertEquals('PNG', substr($generated, 1, 3));
}
/**
* @test
*/
public function 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);
}
/**
* @test
*/
public function 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);
}
/**
* @test
*/
public function jpg_barcode_generator_can_generate_code_128_barcode()
{
$generator = new Picqer\Barcode\BarcodeGeneratorJPG();
$generator->getBarcode('081231723897', $generator::TYPE_CODE_128);
}
/**
* @test
* @expectedException \Picqer\Barcode\Exceptions\InvalidCharacterException
*/
public function ean13_generator_throws_exception_if_invalid_chars_are_used()
{
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
$generator->getBarcode('A123', $generator::TYPE_EAN_13);
}
/**
* @test
*/
public function 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);
}
/**
* @test
*/
public function 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);
}
/**
* @test
*/
public function 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);
}
/**
* @test
* @expectedException \Picqer\Barcode\Exceptions\InvalidCheckDigitException
*/
public function ean13_generator_throws_exception_when_wrong_check_digit_is_given()
{
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
$generator->getBarcode('0049000004633', $generator::TYPE_EAN_13);
}
/**
* @test
* @expectedException \Picqer\Barcode\Exceptions\UnknownTypeException
*/
public function generator_throws_unknown_type_exceptions()
{
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
$generator->getBarcode('0049000004633', 'vladimir');
}
}

View File

@@ -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="black" 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

View File

@@ -0,0 +1,32 @@
<div style="font-size:0;position:relative;width:202px;height:30px;">
<div style="background-color:black;width:4px;height:30px;position:absolute;left:0px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:2px;height:30px;position:absolute;left:6px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:6px;height:30px;position:absolute;left:12px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:2px;height:30px;position:absolute;left:22px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:4px;height:30px;position:absolute;left:30px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:2px;height:30px;position:absolute;left:38px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:2px;height:30px;position:absolute;left:44px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:4px;height:30px;position:absolute;left:48px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:6px;height:30px;position:absolute;left:56px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:4px;height:30px;position:absolute;left:66px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:4px;height:30px;position:absolute;left:72px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:4px;height:30px;position:absolute;left:82px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:2px;height:30px;position:absolute;left:88px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:4px;height:30px;position:absolute;left:94px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:2px;height:30px;position:absolute;left:106px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:2px;height:30px;position:absolute;left:110px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:4px;height:30px;position:absolute;left:118px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:2px;height:30px;position:absolute;left:128px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:8px;height:30px;position:absolute;left:132px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:2px;height:30px;position:absolute;left:142px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:2px;height:30px;position:absolute;left:146px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:6px;height:30px;position:absolute;left:154px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:2px;height:30px;position:absolute;left:162px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:4px;height:30px;position:absolute;left:166px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:4px;height:30px;position:absolute;left:176px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:6px;height:30px;position:absolute;left:186px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:2px;height:30px;position:absolute;left:194px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:4px;height:30px;position:absolute;left:198px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:0px;height:30px;position:absolute;left:202px;top:0px;">&nbsp;</div>
<div style="background-color:black;width:0px;height:30px;position:absolute;left:202px;top:0px;">&nbsp;</div>
</div>

View File

@@ -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="black" 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