Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions barcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@ function barcode( $filepath="", $text="0", $size="20", $orientation="horizontal"
$code_string .= $code_array[$code_keys[($chksum - (intval($chksum / 103) * 103))]];

$code_string = "211412" . $code_string . "2331112";
} elseif ( strtolower($code_type) == "code128c" ) {
$chksum = 105;
// Must not change order of array elements as the checksum depends on the array's key to validate final code
$code_array = array('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', 'FNC 4' => '311141', 'FNC 1' => '411131', 'Start A' => '211412', 'Start B' => '211214', 'Start C' => '211232', 'Stop' => '2331112');
$code_keys = array_keys($code_array);
$code_values = array_flip($code_keys);
$code = preg_replace('/[^0-9]/', '', $text); // Code 128C supports numbers only

$i = 1;
for ( $X = 1; $X <= strlen($code); $X += 2 ) {
$activeKey = substr( $code, ($X-1), 2);
$code_string .= $code_array[$activeKey];
$chksum = ($chksum + ($code_values[$activeKey] * $i));
$i++;
}

$code_string .= $code_array[$code_keys[($chksum - (intval($chksum / 103) * 103))]];

$code_string = "211232" . $code_string . "2331112";
} elseif ( strtolower($code_type) == "code39" ) {
$code_array = array("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");

Expand Down