PK
®’5; Image_Barcode-1.1.0/PK
¯’5; Image_Barcode-1.1.0/Barcode/PK
š’5;9ÃÌS! S! % Image_Barcode-1.1.0/Barcode/imbjp.php
* @copyright 2009 Kuroneko Square
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version v 0.1
* @link http://pear.php.net/package/Image_Barcode
*/
/*
* Note:
*
* The generated barcode must fit the following criteria to be useable
* by the JapanPost scanners:
*
* When printed, the dimensions should be:
*
* full bar: 3.6 mm
* short bar: 1.2 mm
* bar pitch: 1.2 mm
*/
require_once '/Image/Barcode.php';
/**
* Image_Barcode_imbjp class
*
* Package which provides a method to create PostNet barcode using GD library.
*
* @category Image
* @package Image_Barcode
* @author Kuroneko Square
* @copyright 2009 Kuroneko Square
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version v 0.1
* @link http://pear.php.net/package/Image_Barcode
*/
class Image_Barcode_imbjp extends Image_Barcode
{
/**
* Barcode type
* @var string
*/
var $_type = 'imb';
/**
* Bar ascender height
*
* @var integer
*/
var $_barascenderheight = 8;
/**
* Bar descender height
*
* @var integer
*/
var $_bardescenderheight = 4;
/**
* Bar full height
*
* @var integer
*/
var $_barfullheight = 12;
/**
* Bar width / scaling factor
*
* @var integer
*/
var $_barwidth = 2;
/**
* Coding map
* @var array
*/
var $_coding_map = array(
'0' => '144',
'1' => '114',
'2' => '132',
'3' => '312',
'4' => '123',
'5' => '141',
'6' => '321',
'7' => '213',
'8' => '231',
'9' => '411',
'-' => '414',
'10' => '414',
'11' => '324',
'12' => '342',
'13' => '234',
'14' => '432',
'15' => '243',
'16' => '423',
'17' => '441',
'18' => '111',
/*'CC1' => '324',
'CC2' => '342',
'CC3' => '234',
'CC4' => '432',
'CC5' => '243',
'CC6' => '423',
'CC7' => '441',
'CC8' => '111',*/
'leader' => '13',
'trailer' => '31',
'A' => '324144',
'B' => '324114',
'C' => '324132',
'D' => '324312',
'E' => '324123',
'F' => '324141',
'G' => '324321',
'H' => '324213',
'I' => '324231',
'J' => '324411',
'K' => '342144',
'L' => '342114',
'M' => '342132',
'N' => '342312',
'O' => '342123',
'P' => '342141',
'Q' => '342321',
'R' => '342213',
'S' => '342231',
'T' => '342411',
'U' => '234144',
'V' => '234114',
'W' => '234132',
'X' => '234312',
'Y' => '234123',
'Z' => '234141'
);
/**
* Check Digit coding map
* @var array
*/
var $_checkdg_map = array(
'144' => '0',
'114' => '1',
'132' => '2',
'312' => '3',
'123' => '4',
'141' => '5',
'321' => '6',
'213' => '7',
'231' => '8',
'411' => '9',
'414' => '10',
'324' => '11',
'342' => '12',
'234' => '13',
'432' => '14',
'243' => '15',
'423' => '16',
'441' => '17',
'111' => '18'
);
/**
* Draws a PostNet image barcode
*
* @param string $text A text that should be in the image barcode
* @param string $imgtype The image type that will be generated
*
* @return image The barcode
*
* @access public
*
* @author Kuroneko Square
* @since Image_Barcode 0.3
*/
function draw($text, $imgtype = 'png')
{
$numstring = $this->validator_imbjp($text);
// Calculate the barcode width
$barcodewidth = 21 * 6 * $this->_barwidth + $this->_barwidth*7; //bar=2->266
// Create the image
$img = ImageCreate($barcodewidth, $this->_barfullheight);
// Alocate the black and white colors
$black = ImageColorAllocate($img, 0, 0, 0);
$white = ImageColorAllocate($img, 255, 255, 255);
// Fill image with white color
imagefill($img, 0, 0, $white);
// Initiate x position
$xpos = 0;
// Draw $text contents
for ($baridx = 0; $baridx < 71; $baridx++) { // 71 = leader + num + checkdigit + trailer
$nu = substr($numstring, $baridx, 1);
switch($nu){
case 1:
$elementheight = 0;
$this->_barheight = $this->_barfullheight;
break;
case 2:
$elementheight = 0;
$this->_barheight = $this->_barascenderheight;
break;
case 3:
$elementheight = $this->_bardescenderheight;
$this->_barheight = $this->_barfullheight;
break;
case 4:
$elementheight = $this->_bardescenderheight;
$this->_barheight = $this->_barascenderheight;
break;
}
imagefilledrectangle($img, $xpos, $elementheight, $xpos + $this->_barwidth - 1, $this->_barheight, $black);
$xpos += 2*$this->_barwidth;
}
return $img;
/*header('Content-type: image/gif');
imagepng($img);
imagedestroy($img);*/
}
/**
* Return the validated IMBJP string.
*/
function validator_imbjp($text){
$text = trim($text);
$text = strtoupper($text);
$rep_pat= array("&","/","・",".");
$text = str_replace($rep_pat,'',$text);
$text = preg_replace('/[A-Z]{2,}/','',$text);
// /[0-9]F/ -> [0-9]-, 2-3-$ => 2-3
if(preg_match_all('/[0-9]F/',$text, $matches)){
foreach($matches[0] as $key => $value){
$mat[$key] = str_replace('F','-',$value);
}
$text = str_replace($matches[0],$mat,$text);
$text = preg_replace('/-$/','',$text);
}
if(preg_match_all('/[A-Z0-9\-]+/', $text, $matches)){
$text = implode('-', $matches[0]);
} else {
return;
}
// A-2 => A2, L-B => LB
if(preg_match_all('/-*[A-Z]-*/',$text, $matches)){
foreach($matches[0] as $key => $value){
$mat[$key] = str_replace('-','',$value);
}
$text = str_replace($matches[0],$mat,$text);
}
$text = str_replace('--','-',$text);
if(substr($text,3,1)=='-'){
$text = substr_replace($text,'',3,1);
}
if(substr($text,7,1)=='-'){
$text = substr_replace($text,'',7,1);
}
//numstring
for ($idx = 0; $idx < strlen($text); $idx++) {
$char = substr($text, $idx, 1);
for ($baridx = 0; $baridx < strlen($this->_coding_map[$char]);) {
$numstring[] = substr($this->_coding_map[$char], $baridx, 3);
$baridx = $baridx+3;
}
}
//numstring length check(add and remove)
if(count($numstring) < 20){
for($idx = count($numstring); $idx < 20; $idx++){
$numstring[] = '432';
}
}
$numstring = array_slice($numstring,0,20);
//Check digit
foreach($numstring as $value) {
$checksum = $checksum + $this->_checkdg_map[$value];
}
if(($checksum % 19) == 0) {
$checkdigit = 0;
} else {
$checkdigit = (19 - ($checksum % 19));
}
//leader + number + checkdigit + trailer
$numstring = $this->_coding_map['leader'].implode('',$numstring).$this->_coding_map[$checkdigit].$this->_coding_map['trailer'];
return $numstring;
}
} // class
?>PK
®’5; Image_Barcode-1.1.0/PK
¯’5; 2 Image_Barcode-1.1.0/Barcode/PK
š’5;9ÃÌS! S! % l Image_Barcode-1.1.0/Barcode/imbjp.phpPK ß "