社区
PHP
帖子详情
php 中生成8位条形码
nwliu
2009-01-03 03:43:35
各位大侠:
本人有一急需,根据给定的8位数字如“71020034”生成条形码,不需要校验码位,条码就显示给定的8位数字,扫描使用。EAN-13的不要给,谢了。
...全文
695
16
打赏
收藏
php 中生成8位条形码
各位大侠: 本人有一急需,根据给定的8位数字如“71020034”生成条形码,不需要校验码位,条码就显示给定的8位数字,扫描使用。EAN-13的不要给,谢了。
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
16 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
xuexihappy_Dtw
2009-01-09
打赏
举报
回复
up
宇晨007
2009-01-09
打赏
举报
回复
强,顶
frj000
2009-01-08
打赏
举报
回复
呵呵。。不错。。顶起来!@
yctin
2009-01-05
打赏
举报
回复
http://www.aditus.nu/jpgraph/features.php
whalefish2001
2009-01-05
打赏
举报
回复
呵呵,进来看看,顺便顶起来。
wzwen
2009-01-05
打赏
举报
回复
进来学习中....
iasky
2009-01-03
打赏
举报
回复
google,很多
Zijian_Zhang
2009-01-03
打赏
举报
回复
居然是打印出来的,我还没讲过用PHP打印数据的呢??
fxs_2008
2009-01-03
打赏
举报
回复
原来要的是打印出来的图片,收藏了
fxs_2008
2009-01-03
打赏
举报
回复
学习,条码还是验证码?
条码是不是唯一啊!
dzxccsu
2009-01-03
打赏
举报
回复
改好了
<?php
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) != 8 ) { die("UPC-A Must be 8 digits."); }
/* Compute the EAN-13 Checksum digit */
$ncode = '0'.$code;
$even = 0; $odd = 0;
for ($x=0;$x<9;$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<6;$x++)
{
$bars.=$Lencode[$code[$x]];
}
$bars.=$center;
for($x=6;$x<9;$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<strlen($bars);$x++)
{
if (($x<10) || ($x>=45 && $x<50) || ($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<5;$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('71020034');
?>
nwliu
2009-01-03
打赏
举报
回复
以下是我的代码,改动了你说的从12到9,程序出错。麻烦您帮忙调一下好吗,谢了!
<?php
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) != 8 ) { die("UPC-A Must be 11 digits."); }
/* Compute the EAN-13 Checksum digit */
$ncode = '0'.$code;
$even = 0; $odd = 0;
for ($x=0;$x<9;$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<6;$x++) {
$bars.=$Lencode[$code[$x]];
}
$bars.=$center;
for($x=6;$x<9;$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<strlen($bars);$x++) {
if (($x<10) || ($x>=45 && $x<50) || ($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<5;$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. */
echo strlen($bars); die("5");
header("Content-Type: image/png");
ImagePNG($img);
}
UPCAbarcode('71010002');
?>
dzxccsu
2009-01-03
打赏
举报
回复
<?php ?>
dzxccsu
2009-01-03
打赏
举报
回复
大哥你改一下就可以拉
1.if ( strlen($code) != 11 ) { die("UPC-A Must be 11 digits."); } =》if ( strlen($code) != 8 ) { die("UPC-A Must be 8 digits."); }
2.for ($x=0;$x<12;$x++)=》for ($x=0;$x<9;$x++)
3.for($x=6;$x<12;$x++)=》for($x=6;$x<9;$x++)
nwliu
2009-01-03
打赏
举报
回复
谢谢大侠,不过这是11位的,我有,需要8位的。!!!请看一下我的要求。
dzxccsu
2009-01-03
打赏
举报
回复
UPCA条码函数。仅供参考
<?php
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<12;$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<6;$x++)
{
$bars.=$Lencode[$code[$x]];
}
$bars.=$center;
for($x=6;$x<12;$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<strlen($bars);$x++)
{
if (($x<10) || ($x>=45 && $x<50) || ($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<5;$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');
?>
在web
生成
条形码
生成
条形码
生成
条形码
在web
生成
条形码
,
生成
条形码
生成
条形码
生成
条形码
生成
条形码
生成
条形码
生成
条形码
php
生成
条形码
php
生成
条形码
支持多种字符 简单实用 不会用的就是没用过
php
php
生成
条形码
接口
php
生成
条形码
接口 非常的好用 只需要按照说明配置,一键
生成
各种
条形码
PHP
生成
条形码
PHP
生成
条形码
,可以通过
PHP
生成
条形码
.简单实用
PHP
生成
条形码
barcode类
PHP
生成
条形码
barcode类
PHP
20,398
社区成员
19,656
社区内容
发帖
与我相关
我的任务
PHP
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
复制链接
扫一扫
分享
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
php
phpstorm
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章