php实现生成code128条形码的方法详解
发布时间:2020-12-12 22:13:36 所属栏目:PHP教程 来源:网络整理
导读:本篇章节讲解php实现生成code128条形码的方法。供大家参考研究具体如下: 效果图: self::STARTA,'B'=>self::STARTB,'C'=>self::STARTC); private $code =''; private $bin_code =''; private $text =''; public function __construct($code='',$te
本篇章节讲解php实现生成code128条形码的方法。分享给大家供大家参考,具体如下: 效果图: self::STARTA,'B'=>self::STARTB,'C'=>self::STARTC);
private $code ='';
private $bin_code ='';
private $text ='';
public function __construct($code='',$text='',$type='B')
{
if (in_array($type,array('A','B','C')))
$this->setType($type);
else
$this->setType('B');
if ($code !=='')
$this->setCode($code);
if ($text !=='')
$this->setText($text);
}
public function setUnitWidth($unit_width)
{
$this->unit_width = $unit_width;
$this->quiet_zone = $this->unit_width*6;
$this->font_height = $this->unit_width*15;
if (!$this->is_set_height)
{
$this->heith = $this->unit_width*35;
}
}
public function setFontType($font_type)
{
$this->font_type = $font_type;
}
public function setBgcolor($bgcoloe)
{
$this->bgcolor = $bgcoloe;
}
public function setColor($color)
{
$this->color = $color;
}
public function setCode($code)
{
if ($code !='')
{
$this->code= $code;
if ($this->text ==='')
$this->text = $code;
}
}
public function setText($text)
{
$this->text = $text;
}
public function setType($type)
{
$this->type = $type;
}
public function setHeight($height)
{
$this->height = $height;
$this->is_set_height = true;
}
private function getValueFromChar($ch)
{
$val = ord($ch);
try
{
if ($this->type =='A')
{
if ($val > 95)
throw new Exception(' illegal barcode character '.$ch.' for code128A in '.__FILE__.' on line '.__LINE__);
if ($val < 32)
$val += 64;
else
$val -=32;
}
elseif ($this->type =='B')
{
if ($val < 32 || $val > 127)
throw new Exception(' illegal barcode character '.$ch.' for code128B in '.__FILE__.' on line '.__LINE__);
else
$val -=32;
}
else
{
if (!is_numeric($ch) || (int)$ch < 0 || (int)($ch) > 99)
throw new Exception(' illegal barcode character '.$ch.' for code128C in '.__FILE__.' on line '.__LINE__);
else
{
if (strlen($ch) ==1)
$ch .='0';
$val = (int)($ch);
}
}
}
catch(Exception $ex)
{
errorlog('die',$ex->getMessage());
}
return $val;
}
private function parseCode()
{
$this->type=='C'?$step=2:$step=1;
$val_sum = $this->start_codes[$this->type];
$this->width = 35;
$this->bin_code = $this->codes[$val_sum];
for($i =0;$i
附加一个强大的条码生成扩展包: http://www.barcodebakery.com/ PS:这里再为大家推荐一款相似的条形码生成工具供大家参考使用: 在线条形码(一维码)生成/实时预览工具: 更多关于PHP相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》及《》 希望本文所述对大家PHP程序设计有所帮助。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |