搜索
首页php教程php手册PHP生成条形码实现程序

PHP生成条形码实现程序

Jun 13, 2016 am 10:01 AM
php多个实现宽度条形码生成程序空白

条形码(barcode)是将宽度不等的多个黑条和空白,按照一定的编码规则排列,用以表达一组信息的图形标识符。常见的条形码是由反射率相差很大的黑条(简称条)和白条(简称空)排成平行线的图案对于上面有个大概的了解后,下面我们可以重新整合下代码,更加方便的使用它。

 代码如下 复制代码
  
function UPCAbarcode($code)
{
    $lw = 2; $hi = 100;
    $Lencode = array('0001101','0011001','0010011','0111101','0100011',
                    '0110001','0101111','0111011','0110111','0001011');
    $Rencode = array('1110010','1100110','1101100','1000010','1011100',
                    '1001110','1010000','1000100','1001000','1110100');
    $ends = '101'; $center = '01010';
  
    /* UPC-A Must be 11 digits, we compute the checksum. */
    if ( strlen($code) != 11 ) { die("UPC-A Must be 11 digits."); }
  
    /* Compute the EAN-13 Checksum digit */
    $ncode = '0'.$code;
    $even = 0; $odd = 0;
    for ($x=0;$x     {
        if ($x % 2) { $odd += $ncode[$x]; } else { $even += $ncode[$x]; }
    }
  
    $code.=(10 - (($odd * 3 + $even) % 10)) % 10;
  
    /* Create the bar encoding using a binary string */
    $bars=$ends;
    $bars.=$Lencode[$code[0]];
    for($x=1;$x     {
        $bars.=$Lencode[$code[$x]];
    }
  
    $bars.=$center;
  
    for($x=6;$x     {
        $bars.=$Rencode[$code[$x]];
    }
  
    $bars.=$ends;
  
    /* Generate the Barcode Image */
    $img = ImageCreate($lw*95+30,$hi+30);
    $fg = ImageColorAllocate($img, 0, 0, 0);
    $bg = ImageColorAllocate($img, 255, 255, 255);
    ImageFilledRectangle($img, 0, 0, $lw*95+30, $hi+30, $bg);
  
    $shift=10;
  
    for ($x=0;$x     {
        if (($x=45 && $x=85)) { $sh=10; } else { $sh=0; }
        if ($bars[$x] == '1') { $color = $fg; } else { $color = $bg; }
        ImageFilledRectangle($img, ($x*$lw)+15,5,($x+1)*$lw+14,$hi+5+$sh,$color);
    }
  
    /* Add the Human Readable Label */
    ImageString($img,4,5,$hi-5,$code[0],$fg);
  
    for ($x=0;$x     {
        ImageString($img,5,$lw*(13+$x*6)+15,$hi+5,$code[$x+1],$fg);
        ImageString($img,5,$lw*(53+$x*6)+15,$hi+5,$code[$x+6],$fg);
    }
  
    ImageString($img,4,$lw*95+17,$hi-5,$code[11],$fg);
  
    /* Output the Header and Content. */
    header("Content-Type: image/png");
    ImagePNG($img);
  
}
  
UPCAbarcode('13322483157');
  
?>
声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具