Creating C128, C39, C25 & Codebar (careful still minor bugs in C128c)

This commit is contained in:
Dennis Eichhorn 2016-02-21 13:29:39 +01:00
parent b94a932080
commit 2df3111c2b
8 changed files with 357 additions and 438 deletions

View File

@ -0,0 +1,112 @@
<?php
namespace phpOMS\Utils\Barcode;
use phpOMS\Datatypes\Exception\InvalidEnumValue;
abstract class C128Abstract
{
protected static $CHECKSUM = 0;
protected static $CODEARRAY = [];
protected static $CODE_START = '';
protected static $CODE_END = '';
protected $orientation = 0;
protected $size = 0;
protected $content = 0;
public function __construct(string $content = '', int $size = 20, int $orientation = 0)
{
$this->content = $content;
$this->setSize($size);
$this->setOrientation($orientation);
}
public function setOrientation(int $orientation)
{
if (!OrientationType::isValidValue($orientation)) {
throw new InvalidEnumValue($orientation);
}
$this->orientation = $orientation;
}
public function setContent(string $content)
{
$this->content = $content;
}
public function setSize(int $size)
{
if ($size < 0) {
throw new \OutOfBoundsException($size);
}
$this->size = $size;
}
protected function generateCodeString()
{
$keys = array_keys(self::$CODEARRAY);
$values = array_flip($keys);
$codeString = '';
$length = strlen($this->content);
$checksum = self::$CHECKSUM;
for ($pos = 1; $pos <= $length; $pos += 2) {
$activeKey = substr($this->content, ($pos - 1), 1);
$codeString .= self::$CODEARRAY[$activeKey];
$checksum = ($checksum + ($values[$activeKey] * $pos));
}
$codeString .= self::$CODEARRAY[$keys[($checksum - (intval($checksum / 103) * 103))]];
$codeString = self::$CODE_START . $codeString . self::$CODE_END;
return $codeString;
}
public function get()
{
$codeString = self::$CODE_START . $this->generateCodeString() . self::$CODE_END;
return $this->createImage($codeString, 20);
}
protected function createImage(string $codeString, int $codeLength = 20)
{
for ($i = 1; $i <= strlen($codeString); $i++) {
$codeLength = $codeLength + (int) (substr($codeString, ($i - 1), 1));
}
if (strtolower($this->orientation) === OrientationType::HORIZONTAL) {
$imgWidth = $codeLength;
$imgHeight = $this->size;
} else {
$imgWidth = $this->size;
$imgHeight = $codeLength;
}
$image = imagecreate($imgWidth, $imgHeight);
$black = imagecolorallocate($image, 0, 0, 0);
$white = imagecolorallocate($image, 255, 255, 255);
$location = 0;
$length = strlen($codeString);
imagefill($image, 0, 0, $white);
for ($position = 1; $position <= $length; $position++) {
$cur_size = $location + (int) (substr($codeString, ($position - 1), 1));
if (strtolower($this->orientation) === OrientationType::HORIZONTAL) {
imagefilledrectangle($image, $location, 0, $cur_size, $imgHeight, ($position % 2 == 0 ? $white : $black));
} else {
imagefilledrectangle($image, 0, $location, $imgWidth, $cur_size, ($position % 2 == 0 ? $white : $black));
}
$location = $cur_size;
}
return $image;
}
}

View File

@ -1,103 +1,44 @@
<?php
class C128
namespace phpOMS\Utils\Barcode;
class C128a extends C128Abstract
{
private $orientation = 0;
private $size = 0;
private $content = 0;
protected static $CHECKSUM = 103;
protected static $CODEARRAY = [
' ' => '212222', '!' => '222122', '"' => '222221', '#' => '121223', '$' => '121322', '%' => '131222',
'&' => '122213', '\'' => '122312', '(' => '132212', ')' => '221213', '*' => '221312', '+' => '231212',
',' => '112232', '-' => '122132', '.' => '122231', '/' => '113222', '0' => '123122', '1' => '123221',
'2' => '223211', '3' => '221132', '4' => '221231', '5' => '213212', '6' => '223112', '7' => '312131',
'8' => '311222', '9' => '321122', ':' => '321221', ';' => '312212', '<' => '322112', '=' => '322211',
'>' => '212123', '?' => '212321', '@' => '232121', 'A' => '111323', 'B' => '131123', 'C' => '131321',
'D' => '112313', 'E' => '132113', 'F' => '132311', 'G' => '211313', 'H' => '231113', 'I' => '231311',
'J' => '112133', 'K' => '112331', 'L' => '132131', 'M' => '113123', 'N' => '113321', 'O' => '133121',
'P' => '313121', 'Q' => '211331', 'R' => '231131', 'S' => '213113', 'T' => '213311', 'U' => '213131',
'V' => '311123', 'W' => '311321', 'X' => '331121', 'Y' => '312113', 'Z' => '312311', '[' => '332111',
'\\' => '314111', ']' => '221411', '^' => '431111', '_' => '111224', 'NUL' => '111422', 'SOH' => '121124',
'STX' => '121421', 'ETX' => '141122', 'EOT' => '141221', 'ENQ' => '112214', 'ACK' => '112412',
'BEL' => '122114', 'BS' => '122411', 'HT' => '142112', 'LF' => '142211', 'VT' => '241211', 'FF' => '221114',
'CR' => '413111', 'SO' => '241112', 'SI' => '134111', 'DLE' => '111242', 'DC1' => '121142',
'DC2' => '121241', 'DC3' => '114212', 'DC4' => '124112', 'NAK' => '124211', 'SYN' => '411212',
'ETB' => '421112', 'CAN' => '421211', 'EM' => '212141', 'SUB' => '214121', 'ESC' => '412121',
'FS' => '111143', 'GS' => '111341', 'RS' => '131141', 'US' => '114113', 'FNC 3' => '114311',
'FNC 2' => '411113', 'SHIFT' => '411311', 'CODE C' => '113141', 'CODE B' => '114131', 'FNC 4' => '311141',
'FNC 1' => '411131', 'Start A' => '211412', 'Start B' => '211214', 'Start C' => '211232',
'Stop' => '2331112',
];
protected static $CODE_START = '211412';
protected static $CODE_END = '2331112';
public function __construct(string $content = '', int $size = 20, int $orientation = 0)
{
$this->content = $content;
$this->size = $size;
$this->orientation = $orientation;
}
public function setOrientation(int $orientation)
{
$this->orientation = $orientation;
parent::__construct(strtoupper($content), $size, $orientation);
}
public function setContent(string $content)
{
$this->content = $content;
}
public function setSize(int $size)
{
$this->size = $size;
}
public function get()
{
$codeString = '';
$chksum = 104;
/* Order is critical for checksum */
$codeArray = [
' ' => '212222', '!' => '222122', '\'' => '222221', '#' => '121223', '$' => '121322', '%' => '131222',
'&' => '122213', '\'' => '122312', '(' => '132212', ')' => '221213', '*' => '221312', '+' => '231212',
',' => '112232', '-' => '122132', '.' => '122231', '/' => '113222', '0' => '123122', '1' => '123221',
'2' => '223211', '3' => '221132', '4' => '221231', '5' => '213212', '6' => '223112', '7' => '312131',
'8' => '311222', '9' => '321122', ':' => '321221', ';' => '312212', '<' => '322112', '=' => '322211',
'>' => '212123', '?' => '212321', '@' => '232121', 'A' => '111323', 'B' => '131123', 'C' => '131321',
'D' => '112313', 'E' => '132113', 'F' => '132311', 'G' => '211313', 'H' => '231113', 'I' => '231311',
'J' => '112133', 'K' => '112331', 'L' => '132131', 'M' => '113123', 'N' => '113321', 'O' => '133121',
'P' => '313121', 'Q' => '211331', 'R' => '231131', 'S' => '213113', 'T' => '213311', 'U' => '213131',
'V' => '311123', 'W' => '311321', 'X' => '331121', 'Y' => '312113', 'Z' => '312311', '[' => '332111',
'\\' => '314111', ']' => '221411', '^' => '431111', '_' => '111224', '\`' => '111422', 'a' => '121124',
'b' => '121421', 'c' => '141122', 'd' => '141221', 'e' => '112214', 'f' => '112412', 'g' => '122114',
'h' => '122411', 'i' => '142112', 'j' => '142211', 'k' => '241211', 'l' => '221114', 'm' => '413111',
'n' => '241112', 'o' => '134111', 'p' => '111242', 'q' => '121142', 'r' => '121241', 's' => '114212',
't' => '124112', 'u' => '124211', 'v' => '411212', 'w' => '421112', 'x' => '421211', 'y' => '212141',
'z' => '214121', '{' => '412121', '|' => '111143', '}' => '111341', '~' => '131141', 'DEL' => '114113',
'FNC 3' => '114311', 'FNC 2' => '411113', 'SHIFT' => '411311', 'CODE C' => '113141', 'FNC 4' => '114131',
'CODE A' => '311141', 'FNC 1' => '411131', 'Start A' => '211412', 'Start B' => '211214',
'Start C' => '211232', 'Stop' => '2331112',
];
$codeKeys = array_keys($codeArray);
$codeValues = array_flip($codeKeys);
for ($X = 1; $X <= strlen($this->content); $X++) {
$activeKey = substr($this->content, ($X - 1), 1);
$codeString .= $codeArray[$activeKey];
$chksum = ($chksum + ($codeValues[$activeKey] * $X));
}
$codeString .= $codeArray[$codeKeys[($chksum - (intval($chksum / 103) * 103))]];
$codeString = '211214' . $codeString . '2331112';
$codeLength = 20;
for ($i = 1; $i <= strlen($codeString); $i++) {
$codeLength = $codeLength + (integer) (substr($codeString, ($i - 1), 1));
}
if (strtolower($this->orientation) == 'horizontal') {
$imgWidth = $codeLength;
$imgHeight = $this->size;
} else {
$imgWidth = $this->size;
$imgHeight = $codeLength;
}
$image = imagecreate($imgWidth, $imgHeight);
$black = imagecolorallocate($image, 0, 0, 0);
$white = imagecolorallocate($image, 255, 255, 255);
$location = 0;
imagefill($image, 0, 0, $white);
for ($position = 1; $position <= strlen($codeString); $position++) {
$cur_size = $location + (substr($codeString, ($position - 1), 1));
if (strtolower($this->orientation) == 'horizontal') {
imagefilledrectangle($image, $location, 0, $cur_size, $imgHeight, ($position % 2 == 0 ? $white : $black));
} else {
imagefilledrectangle($image, 0, $location, $imgWidth, $cur_size, ($position % 2 == 0 ? $white : $black));
}
$location = $cur_size;
}
return $image;
parent::setContent(strtoupper($content));
}
}

View File

@ -1,103 +1,33 @@
<?php
class C128
namespace phpOMS\Utils\Barcode;
class C128b extends C128Abstract
{
private $orientation = 0;
private $size = 0;
private $content = 0;
protected static $CHECKSUM = 104;
public function __construct(string $content = '', int $size = 20, int $orientation = 0)
{
$this->content = $content;
$this->size = $size;
$this->orientation = $orientation;
}
protected static $CODEARRAY = [
' ' => '212222', '!' => '222122', '"' => '222221', '#' => '121223', '$' => '121322', '%' => '131222',
'&' => '122213', '\'' => '122312', '(' => '132212', ')' => '221213', '*' => '221312', '+' => '231212',
',' => '112232', '-' => '122132', '.' => '122231', '/' => '113222', '0' => '123122', '1' => '123221',
'2' => '223211', '3' => '221132', '4' => '221231', '5' => '213212', '6' => '223112', '7' => '312131',
'8' => '311222', '9' => '321122', ':' => '321221', ';' => '312212', '<' => '322112', '=' => '322211',
'>' => '212123', '?' => '212321', '@' => '232121', 'A' => '111323', 'B' => '131123', 'C' => '131321',
'D' => '112313', 'E' => '132113', 'F' => '132311', 'G' => '211313', 'H' => '231113', 'I' => '231311',
'J' => '112133', 'K' => '112331', 'L' => '132131', 'M' => '113123', 'N' => '113321', 'O' => '133121',
'P' => '313121', 'Q' => '211331', 'R' => '231131', 'S' => '213113', 'T' => '213311', 'U' => '213131',
'V' => '311123', 'W' => '311321', 'X' => '331121', 'Y' => '312113', 'Z' => '312311', '[' => '332111',
'\\' => '314111', ']' => '221411', '^' => '431111', '_' => '111224', '`' => '111422', 'a' => '121124',
'b' => '121421', 'c' => '141122', 'd' => '141221', 'e' => '112214', 'f' => '112412', 'g' => '122114',
'h' => '122411', 'i' => '142112', 'j' => '142211', 'k' => '241211', 'l' => '221114', 'm' => '413111',
'n' => '241112', 'o' => '134111', 'p' => '111242', 'q' => '121142', 'r' => '121241', 's' => '114212',
't' => '124112', 'u' => '124211', 'v' => '411212', 'w' => '421112', 'x' => '421211', 'y' => '212141',
'z' => '214121', '{' => '412121', '|' => '111143', '}' => '111341', '~' => '131141', 'DEL' => '114113',
'FNC 3' => '114311', 'FNC 2' => '411113', 'SHIFT' => '411311', 'CODE C' => '113141', 'FNC 4' => '114131',
'CODE A' => '311141', 'FNC 1' => '411131', 'Start A' => '211412', 'Start B' => '211214',
'Start C' => '211232', 'Stop' => '2331112',
];
public function setOrientation(int $orientation)
{
$this->orientation = $orientation;
}
public function setContent(string $content)
{
$this->content = $content;
}
public function setSize(int $size)
{
$this->size = $size;
}
public function get()
{
$codeString = '';
$chksum = 104;
/* Order is critical for checksum */
$codeArray = [
' ' => '212222', '!' => '222122', '\'' => '222221', '#' => '121223', '$' => '121322', '%' => '131222',
'&' => '122213', '\'' => '122312', '(' => '132212', ')' => '221213', '*' => '221312', '+' => '231212',
',' => '112232', '-' => '122132', '.' => '122231', '/' => '113222', '0' => '123122', '1' => '123221',
'2' => '223211', '3' => '221132', '4' => '221231', '5' => '213212', '6' => '223112', '7' => '312131',
'8' => '311222', '9' => '321122', ':' => '321221', ';' => '312212', '<' => '322112', '=' => '322211',
'>' => '212123', '?' => '212321', '@' => '232121', 'A' => '111323', 'B' => '131123', 'C' => '131321',
'D' => '112313', 'E' => '132113', 'F' => '132311', 'G' => '211313', 'H' => '231113', 'I' => '231311',
'J' => '112133', 'K' => '112331', 'L' => '132131', 'M' => '113123', 'N' => '113321', 'O' => '133121',
'P' => '313121', 'Q' => '211331', 'R' => '231131', 'S' => '213113', 'T' => '213311', 'U' => '213131',
'V' => '311123', 'W' => '311321', 'X' => '331121', 'Y' => '312113', 'Z' => '312311', '[' => '332111',
'\\' => '314111', ']' => '221411', '^' => '431111', '_' => '111224', '\`' => '111422', 'a' => '121124',
'b' => '121421', 'c' => '141122', 'd' => '141221', 'e' => '112214', 'f' => '112412', 'g' => '122114',
'h' => '122411', 'i' => '142112', 'j' => '142211', 'k' => '241211', 'l' => '221114', 'm' => '413111',
'n' => '241112', 'o' => '134111', 'p' => '111242', 'q' => '121142', 'r' => '121241', 's' => '114212',
't' => '124112', 'u' => '124211', 'v' => '411212', 'w' => '421112', 'x' => '421211', 'y' => '212141',
'z' => '214121', '{' => '412121', '|' => '111143', '}' => '111341', '~' => '131141', 'DEL' => '114113',
'FNC 3' => '114311', 'FNC 2' => '411113', 'SHIFT' => '411311', 'CODE C' => '113141', 'FNC 4' => '114131',
'CODE A' => '311141', 'FNC 1' => '411131', 'Start A' => '211412', 'Start B' => '211214',
'Start C' => '211232', 'Stop' => '2331112',
];
$codeKeys = array_keys($codeArray);
$codeValues = array_flip($codeKeys);
for ($X = 1; $X <= strlen($this->content); $X++) {
$activeKey = substr($this->content, ($X - 1), 1);
$codeString .= $codeArray[$activeKey];
$chksum = ($chksum + ($codeValues[$activeKey] * $X));
}
$codeString .= $codeArray[$codeKeys[($chksum - (intval($chksum / 103) * 103))]];
$codeString = '211214' . $codeString . '2331112';
$codeLength = 20;
for ($i = 1; $i <= strlen($codeString); $i++) {
$codeLength = $codeLength + (integer) (substr($codeString, ($i - 1), 1));
}
if (strtolower($this->orientation) == 'horizontal') {
$imgWidth = $codeLength;
$imgHeight = $this->size;
} else {
$imgWidth = $this->size;
$imgHeight = $codeLength;
}
$image = imagecreate($imgWidth, $imgHeight);
$black = imagecolorallocate($image, 0, 0, 0);
$white = imagecolorallocate($image, 255, 255, 255);
$location = 0;
imagefill($image, 0, 0, $white);
for ($position = 1; $position <= strlen($codeString); $position++) {
$cur_size = $location + (substr($codeString, ($position - 1), 1));
if (strtolower($this->orientation) == 'horizontal') {
imagefilledrectangle($image, $location, 0, $cur_size, $imgHeight, ($position % 2 == 0 ? $white : $black));
} else {
imagefilledrectangle($image, 0, $location, $imgWidth, $cur_size, ($position % 2 == 0 ? $white : $black));
}
$location = $cur_size;
}
return $image;
}
protected static $CODE_START = '211214';
protected static $CODE_END = '2331112';
}

62
Utils/Barcode/C128c.php Normal file
View File

@ -0,0 +1,62 @@
<?php
namespace phpOMS\Utils\Barcode;
/**
* Class C128c
* @fixme: here is still a small error. It has a minor deviation to a correct 128c code. WHY?
*/
class C128c extends C128Abstract
{
protected static $CHECKSUM = 105;
protected static $CODEARRAY = [
'00' => '212222', '01' => '222122', '02' => '222221', '03' => '121223', '04' => '121322', '05' => '131222',
'06' => '122213', '07' => '122312', '08' => '132212', '09' => '221213', '10' => '221312', '11' => '231212',
'12' => '112232', '13' => '122132', '14' => '122231', '15' => '113222', '16' => '123122', '17' => '123221',
'18' => '223211', '19' => '221132', '20' => '221231', '21' => '213212', '22' => '223112', '23' => '312131',
'24' => '311222', '25' => '321122', '26' => '321221', '27' => '312212', '28' => '322112', '29' => '322211',
'30' => '212123', '31' => '212321', '32' => '232121', '33' => '111323', '34' => '131123', '35' => '131321',
'36' => '112313', '37' => '132113', '38' => '132311', '39' => '211313', '40' => '231113', '41' => '231311',
'42' => '112133', '43' => '112331', '44' => '132131', '45' => '113123', '46' => '113321', '47' => '133121',
'48' => '313121', '49' => '211331', '50' => '231131', '51' => '213113', '52' => '213311', '53' => '213131',
'54' => '311123', '55' => '311321', '56' => '331121', '57' => '312113', '58' => '312311', '59' => '332111',
'60' => '314111', '61' => '221411', '62' => '431111', '63' => '111224', '64' => '111422', '65' => '121124',
'66' => '121421', '67' => '141122', '68' => '141221', '69' => '112214', '70' => '112412', '71' => '122114',
'72' => '122411', '73' => '142112', '74' => '142211', '75' => '241211', '76' => '221114', '77' => '413111',
'78' => '241112', '79' => '134111', '80' => '111242', '81' => '121142', '82' => '121241', '83' => '114212',
'84' => '124112', '85' => '124211', '86' => '411212', '87' => '421112', '88' => '421211', '89' => '212141',
'90' => '214121', '91' => '412121', '92' => '111143', '93' => '111341', '94' => '131141', '95' => '114113',
'96' => '114311', '97' => '411113', '98' => '411311', '99' => '113141', 'CODE B' => '114131',
'CODE A' => '311141', 'FNC 1' => '411131', 'Start A' => '211412', 'Start B' => '211214', 'Start C' => '211232',
'Stop' => '2331112',
];
protected static $CODE_START = '211232';
protected static $CODE_END = '2331112';
protected function generateCodeString()
{
$keys = array_keys(self::$CODEARRAY);
$values = array_flip($keys);
$codeString = '';
$length = strlen($this->content);
$checksum = self::$CHECKSUM;
for ($pos = 1; $pos <= $length; $pos += 2) {
if ($pos + 1 <= $length) {
$activeKey = substr($this->content, ($pos - 1), 2);
} else {
$activeKey = substr($this->content, ($pos - 1), 1) . '0';
}
$codeString .= self::$CODEARRAY[$activeKey];
$checksum = ($checksum + ($values[$activeKey] * $pos));
}
$codeString .= self::$CODEARRAY[$keys[($checksum - (intval($checksum / 103) * 103))]];
return $codeString;
}
}

View File

@ -1,103 +1,62 @@
<?php
class C128
namespace phpOMS\Utils\Barcode;
class C25 extends C128Abstract
{
private $orientation = 0;
private $size = 0;
private $content = 0;
protected static $CODEARRAY = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];
protected static $CODEARRAY2 = [
'3-1-1-1-3', '1-3-1-1-3', '3-3-1-1-1', '1-1-3-1-3', '3-1-3-1-1',
'1-3-3-1-1', '1-1-1-3-3', '3-1-1-3-1', '1-3-1-3-1', '1-1-3-3-1',
];
protected static $CODE_START = '1111';
protected static $CODE_END = '311';
public function __construct(string $content = '', int $size = 20, int $orientation = 0)
{
$this->content = $content;
$this->size = $size;
$this->orientation = $orientation;
}
if(!ctype_digit($content)) {
throw new \InvalidArgumentException($content);
}
public function setOrientation(int $orientation)
{
$this->orientation = $orientation;
parent::__construct($content, $size, $orientation);
}
public function setContent(string $content)
{
$this->content = $content;
if(!ctype_digit($content)) {
throw new \InvalidArgumentException($content);
}
parent::setContent($content);
}
public function setSize(int $size)
protected function generateCodeString()
{
$this->size = $size;
}
$codeString = '';
$length = strlen($this->content);
$arrayLength = count(self::$CODEARRAY);
public function get()
{
$codeString = '';
$chksum = 104;
/* Order is critical for checksum */
$codeArray = [
' ' => '212222', '!' => '222122', '\'' => '222221', '#' => '121223', '$' => '121322', '%' => '131222',
'&' => '122213', '\'' => '122312', '(' => '132212', ')' => '221213', '*' => '221312', '+' => '231212',
',' => '112232', '-' => '122132', '.' => '122231', '/' => '113222', '0' => '123122', '1' => '123221',
'2' => '223211', '3' => '221132', '4' => '221231', '5' => '213212', '6' => '223112', '7' => '312131',
'8' => '311222', '9' => '321122', ':' => '321221', ';' => '312212', '<' => '322112', '=' => '322211',
'>' => '212123', '?' => '212321', '@' => '232121', 'A' => '111323', 'B' => '131123', 'C' => '131321',
'D' => '112313', 'E' => '132113', 'F' => '132311', 'G' => '211313', 'H' => '231113', 'I' => '231311',
'J' => '112133', 'K' => '112331', 'L' => '132131', 'M' => '113123', 'N' => '113321', 'O' => '133121',
'P' => '313121', 'Q' => '211331', 'R' => '231131', 'S' => '213113', 'T' => '213311', 'U' => '213131',
'V' => '311123', 'W' => '311321', 'X' => '331121', 'Y' => '312113', 'Z' => '312311', '[' => '332111',
'\\' => '314111', ']' => '221411', '^' => '431111', '_' => '111224', '\`' => '111422', 'a' => '121124',
'b' => '121421', 'c' => '141122', 'd' => '141221', 'e' => '112214', 'f' => '112412', 'g' => '122114',
'h' => '122411', 'i' => '142112', 'j' => '142211', 'k' => '241211', 'l' => '221114', 'm' => '413111',
'n' => '241112', 'o' => '134111', 'p' => '111242', 'q' => '121142', 'r' => '121241', 's' => '114212',
't' => '124112', 'u' => '124211', 'v' => '411212', 'w' => '421112', 'x' => '421211', 'y' => '212141',
'z' => '214121', '{' => '412121', '|' => '111143', '}' => '111341', '~' => '131141', 'DEL' => '114113',
'FNC 3' => '114311', 'FNC 2' => '411113', 'SHIFT' => '411311', 'CODE C' => '113141', 'FNC 4' => '114131',
'CODE A' => '311141', 'FNC 1' => '411131', 'Start A' => '211412', 'Start B' => '211214',
'Start C' => '211232', 'Stop' => '2331112',
];
$codeKeys = array_keys($codeArray);
$codeValues = array_flip($codeKeys);
for ($X = 1; $X <= strlen($this->content); $X++) {
$activeKey = substr($this->content, ($X - 1), 1);
$codeString .= $codeArray[$activeKey];
$chksum = ($chksum + ($codeValues[$activeKey] * $X));
}
$codeString .= $codeArray[$codeKeys[($chksum - (intval($chksum / 103) * 103))]];
$codeString = '211214' . $codeString . '2331112';
$codeLength = 20;
for ($i = 1; $i <= strlen($codeString); $i++) {
$codeLength = $codeLength + (integer) (substr($codeString, ($i - 1), 1));
}
if (strtolower($this->orientation) == 'horizontal') {
$imgWidth = $codeLength;
$imgHeight = $this->size;
} else {
$imgWidth = $this->size;
$imgHeight = $codeLength;
}
$image = imagecreate($imgWidth, $imgHeight);
$black = imagecolorallocate($image, 0, 0, 0);
$white = imagecolorallocate($image, 255, 255, 255);
$location = 0;
imagefill($image, 0, 0, $white);
for ($position = 1; $position <= strlen($codeString); $position++) {
$cur_size = $location + (substr($codeString, ($position - 1), 1));
if (strtolower($this->orientation) == 'horizontal') {
imagefilledrectangle($image, $location, 0, $cur_size, $imgHeight, ($position % 2 == 0 ? $white : $black));
} else {
imagefilledrectangle($image, 0, $location, $imgWidth, $cur_size, ($position % 2 == 0 ? $white : $black));
for ($posX = 1; $posX <= $length; $posX++) {
for ($posY = 0; $posY < $arrayLength; $posY++) {
if (substr($this->content, ($posX - 1), 1) == self::$CODEARRAY[$posY]) {
$temp[$posX] = self::$CODEARRAY2[$posY];
}
}
$location = $cur_size;
}
return $image;
for ($posX = 1; $posX <= $length; $posX += 2) {
if (isset($temp[$posX]) && isset($temp[($posX + 1)])) {
$temp1 = explode('-', $temp[$posX]);
$temp2 = explode('-', $temp[($posX + 1)]);
for ($posY = 0; $posY < count($temp1); $posY++) {
$codeString .= $temp1[$posY] . $temp2[$posY];
}
}
}
return $codeString;
}
}

View File

@ -1,103 +1,45 @@
<?php
class C128
namespace phpOMS\Utils\Barcode;
class C39 extends C128Abstract
{
private $orientation = 0;
private $size = 0;
private $content = 0;
protected static $CODEARRAY = [
'0' => '111221211', '1' => '211211112', '2' => '112211112', '3' => '212211111', '4' => '111221112',
'5' => '211221111', '6' => '112221111', '7' => '111211212', '8' => '211211211', '9' => '112211211',
'A' => '211112112', 'B' => '112112112', 'C' => '212112111', 'D' => '111122112', 'E' => '211122111',
'F' => '112122111', 'G' => '111112212', 'H' => '211112211', 'I' => '112112211', 'J' => '111122211',
'K' => '211111122', 'L' => '112111122', 'M' => '212111121', 'N' => '111121122', 'O' => '211121121',
'P' => '112121121', 'Q' => '111111222', 'R' => '211111221', 'S' => '112111221', 'T' => '111121221',
'U' => '221111112', 'V' => '122111112', 'W' => '222111111', 'X' => '121121112', 'Y' => '221121111',
'Z' => '122121111', '-' => '121111212', '.' => '221111211', ' ' => '122111211', '$' => '121212111',
'/' => '121211121', '+' => '121112121', '%' => '111212121', '*' => '121121211',
];
protected static $CODE_START = '1211212111';
protected static $CODE_END = '121121211';
public function __construct(string $content = '', int $size = 20, int $orientation = 0)
{
$this->content = $content;
$this->size = $size;
$this->orientation = $orientation;
}
public function setOrientation(int $orientation)
{
$this->orientation = $orientation;
parent::__construct(strtoupper($content), $size, $orientation);
}
public function setContent(string $content)
{
$this->content = $content;
parent::setContent(strtoupper($content));
}
public function setSize(int $size)
{
$this->size = $size;
}
public function get()
protected function generateCodeString()
{
$codeString = '';
$chksum = 104;
$length = strlen($this->content);
/* Order is critical for checksum */
$codeArray = [
' ' => '212222', '!' => '222122', '\'' => '222221', '#' => '121223', '$' => '121322', '%' => '131222',
'&' => '122213', '\'' => '122312', '(' => '132212', ')' => '221213', '*' => '221312', '+' => '231212',
',' => '112232', '-' => '122132', '.' => '122231', '/' => '113222', '0' => '123122', '1' => '123221',
'2' => '223211', '3' => '221132', '4' => '221231', '5' => '213212', '6' => '223112', '7' => '312131',
'8' => '311222', '9' => '321122', ':' => '321221', ';' => '312212', '<' => '322112', '=' => '322211',
'>' => '212123', '?' => '212321', '@' => '232121', 'A' => '111323', 'B' => '131123', 'C' => '131321',
'D' => '112313', 'E' => '132113', 'F' => '132311', 'G' => '211313', 'H' => '231113', 'I' => '231311',
'J' => '112133', 'K' => '112331', 'L' => '132131', 'M' => '113123', 'N' => '113321', 'O' => '133121',
'P' => '313121', 'Q' => '211331', 'R' => '231131', 'S' => '213113', 'T' => '213311', 'U' => '213131',
'V' => '311123', 'W' => '311321', 'X' => '331121', 'Y' => '312113', 'Z' => '312311', '[' => '332111',
'\\' => '314111', ']' => '221411', '^' => '431111', '_' => '111224', '\`' => '111422', 'a' => '121124',
'b' => '121421', 'c' => '141122', 'd' => '141221', 'e' => '112214', 'f' => '112412', 'g' => '122114',
'h' => '122411', 'i' => '142112', 'j' => '142211', 'k' => '241211', 'l' => '221114', 'm' => '413111',
'n' => '241112', 'o' => '134111', 'p' => '111242', 'q' => '121142', 'r' => '121241', 's' => '114212',
't' => '124112', 'u' => '124211', 'v' => '411212', 'w' => '421112', 'x' => '421211', 'y' => '212141',
'z' => '214121', '{' => '412121', '|' => '111143', '}' => '111341', '~' => '131141', 'DEL' => '114113',
'FNC 3' => '114311', 'FNC 2' => '411113', 'SHIFT' => '411311', 'CODE C' => '113141', 'FNC 4' => '114131',
'CODE A' => '311141', 'FNC 1' => '411131', 'Start A' => '211412', 'Start B' => '211214',
'Start C' => '211232', 'Stop' => '2331112',
];
$codeKeys = array_keys($codeArray);
$codeValues = array_flip($codeKeys);
for ($X = 1; $X <= strlen($this->content); $X++) {
$activeKey = substr($this->content, ($X - 1), 1);
$codeString .= $codeArray[$activeKey];
$chksum = ($chksum + ($codeValues[$activeKey] * $X));
}
$codeString .= $codeArray[$codeKeys[($chksum - (intval($chksum / 103) * 103))]];
$codeString = '211214' . $codeString . '2331112';
$codeLength = 20;
for ($i = 1; $i <= strlen($codeString); $i++) {
$codeLength = $codeLength + (integer) (substr($codeString, ($i - 1), 1));
for ($X = 1; $X <= $length; $X++) {
$codeString .= self::$CODEARRAY[substr($this->content, ($X - 1), 1)] . '1';
}
if (strtolower($this->orientation) == 'horizontal') {
$imgWidth = $codeLength;
$imgHeight = $this->size;
} else {
$imgWidth = $this->size;
$imgHeight = $codeLength;
}
$image = imagecreate($imgWidth, $imgHeight);
$black = imagecolorallocate($image, 0, 0, 0);
$white = imagecolorallocate($image, 255, 255, 255);
$location = 0;
imagefill($image, 0, 0, $white);
for ($position = 1; $position <= strlen($codeString); $position++) {
$cur_size = $location + (substr($codeString, ($position - 1), 1));
if (strtolower($this->orientation) == 'horizontal') {
imagefilledrectangle($image, $location, 0, $cur_size, $imgHeight, ($position % 2 == 0 ? $white : $black));
} else {
imagefilledrectangle($image, 0, $location, $imgWidth, $cur_size, ($position % 2 == 0 ? $white : $black));
}
$location = $cur_size;
}
return $image;
return $codeString;
}
}

View File

@ -1,103 +1,41 @@
<?php
class C128
namespace phpOMS\Utils\Barcode;
class Codebar extends C128Abstract
{
private $orientation = 0;
private $size = 0;
private $content = 0;
protected static $CODEARRAY = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '$', ':', '/', '.', '+', 'A', 'B', 'C', 'D'];
protected static $CODEARRAY2 = [
'1111221', '1112112', '2211111', '1121121', '2111121', '1211112', '1211211', '1221111', '2112111', '1111122',
'1112211', '1122111', '2111212', '2121112', '2121211', '1121212', '1122121', '1212112', '1112122', '1112221',
];
protected static $CODE_START = '11221211';
protected static $CODE_END = '1122121';
public function __construct(string $content = '', int $size = 20, int $orientation = 0)
{
$this->content = $content;
$this->size = $size;
$this->orientation = $orientation;
}
public function setOrientation(int $orientation)
{
$this->orientation = $orientation;
parent::__construct(strtoupper($content), $size, $orientation);
}
public function setContent(string $content)
{
$this->content = $content;
parent::setContent(strtoupper($content));
}
public function setSize(int $size)
{
$this->size = $size;
}
public function get()
protected function generateCodeString()
{
$codeString = '';
$chksum = 104;
$length = strlen($this->content);
/* Order is critical for checksum */
$codeArray = [
' ' => '212222', '!' => '222122', '\'' => '222221', '#' => '121223', '$' => '121322', '%' => '131222',
'&' => '122213', '\'' => '122312', '(' => '132212', ')' => '221213', '*' => '221312', '+' => '231212',
',' => '112232', '-' => '122132', '.' => '122231', '/' => '113222', '0' => '123122', '1' => '123221',
'2' => '223211', '3' => '221132', '4' => '221231', '5' => '213212', '6' => '223112', '7' => '312131',
'8' => '311222', '9' => '321122', ':' => '321221', ';' => '312212', '<' => '322112', '=' => '322211',
'>' => '212123', '?' => '212321', '@' => '232121', 'A' => '111323', 'B' => '131123', 'C' => '131321',
'D' => '112313', 'E' => '132113', 'F' => '132311', 'G' => '211313', 'H' => '231113', 'I' => '231311',
'J' => '112133', 'K' => '112331', 'L' => '132131', 'M' => '113123', 'N' => '113321', 'O' => '133121',
'P' => '313121', 'Q' => '211331', 'R' => '231131', 'S' => '213113', 'T' => '213311', 'U' => '213131',
'V' => '311123', 'W' => '311321', 'X' => '331121', 'Y' => '312113', 'Z' => '312311', '[' => '332111',
'\\' => '314111', ']' => '221411', '^' => '431111', '_' => '111224', '\`' => '111422', 'a' => '121124',
'b' => '121421', 'c' => '141122', 'd' => '141221', 'e' => '112214', 'f' => '112412', 'g' => '122114',
'h' => '122411', 'i' => '142112', 'j' => '142211', 'k' => '241211', 'l' => '221114', 'm' => '413111',
'n' => '241112', 'o' => '134111', 'p' => '111242', 'q' => '121142', 'r' => '121241', 's' => '114212',
't' => '124112', 'u' => '124211', 'v' => '411212', 'w' => '421112', 'x' => '421211', 'y' => '212141',
'z' => '214121', '{' => '412121', '|' => '111143', '}' => '111341', '~' => '131141', 'DEL' => '114113',
'FNC 3' => '114311', 'FNC 2' => '411113', 'SHIFT' => '411311', 'CODE C' => '113141', 'FNC 4' => '114131',
'CODE A' => '311141', 'FNC 1' => '411131', 'Start A' => '211412', 'Start B' => '211214',
'Start C' => '211232', 'Stop' => '2331112',
];
$codeKeys = array_keys($codeArray);
$codeValues = array_flip($codeKeys);
for ($X = 1; $X <= strlen($this->content); $X++) {
$activeKey = substr($this->content, ($X - 1), 1);
$codeString .= $codeArray[$activeKey];
$chksum = ($chksum + ($codeValues[$activeKey] * $X));
}
$codeString .= $codeArray[$codeKeys[($chksum - (intval($chksum / 103) * 103))]];
$codeString = '211214' . $codeString . '2331112';
$codeLength = 20;
for ($i = 1; $i <= strlen($codeString); $i++) {
$codeLength = $codeLength + (integer) (substr($codeString, ($i - 1), 1));
}
if (strtolower($this->orientation) == 'horizontal') {
$imgWidth = $codeLength;
$imgHeight = $this->size;
} else {
$imgWidth = $this->size;
$imgHeight = $codeLength;
}
$image = imagecreate($imgWidth, $imgHeight);
$black = imagecolorallocate($image, 0, 0, 0);
$white = imagecolorallocate($image, 255, 255, 255);
$location = 0;
imagefill($image, 0, 0, $white);
for ($position = 1; $position <= strlen($codeString); $position++) {
$cur_size = $location + (substr($codeString, ($position - 1), 1));
if (strtolower($this->orientation) == 'horizontal') {
imagefilledrectangle($image, $location, 0, $cur_size, $imgHeight, ($position % 2 == 0 ? $white : $black));
} else {
imagefilledrectangle($image, 0, $location, $imgWidth, $cur_size, ($position % 2 == 0 ? $white : $black));
for ($posX = 1; $posX <= $length; $posX++) {
for ($posY = 0; $posY < count(self::$CODEARRAY); $posY++) {
if (substr($this->content, ($posX - 1), 1) == self::$CODEARRAY[$posY])
$codeString .= self::$CODEARRAY2[$posY] . '1';
}
$location = $cur_size;
}
return $image;
return $codeString;
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Utils\Barcode;
use phpOMS\Datatypes\Enum;
/**
* Account type enum.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class OrientationType extends Enum
{
const HORIZONTAL = 0;
const VERTICAL = 1;
}