社区
PHP
帖子详情
php 中生成8位条形码
nwliu
2009-01-03 03:43:35
各位大侠:
本人有一急需,根据给定的8位数字如“71020034”生成条形码,不需要校验码位,条码就显示给定的8位数字,扫描使用。EAN-13的不要给,谢了。
...全文
700
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应用
中
,通常会使用服务器端语言(如Java、
PHP
、Python等)来处理
生成
条形码
的逻辑,然后将
生成
的图片以二进制流的形式发送到客户端,客户端浏览器接收到后显示出来。例如,对于Java,可以使用Servlet或者...
php
生成
条形码
总结起来,
PHP
生成
条形码
的过程涉及选择合适的库、数据编码、图像
生成
、样式定制以及前端展示等多个步骤。通过熟练掌握这些知识点,你可以方便地在
PHP
项目
中
实现
条形码
功能,提升数据处理的效率和用户体验。
php
生成
条形码
接口
总的来说,"
php
生成
条形码
接口"是一个方便的工具,它简化了在
PHP
项目
中
实现
条形码
功能的过程。通过理解和配置这个接口,开发者能够快速地将
条形码
集成到自己的应用程序
中
,提升系统的功能性与用户体验。在实践
中
,...
PHP
生成
条形码
本文将深入探讨如何使用
PHP
生成
条形码
,以及相关的技术细节。 一、
条形码
简介
条形码
是一种自动识别技术,它通过将数字编码为宽度不等的黑色和白色条纹来表示信息。这种编码方式使得数据能够快速准确地被扫描设备...
PHP
生成
条形码
barcode类
"
PHP
生成
条形码
barcode类"指的是使用
PHP
编程语言
中
的特定类库来创建
条形码
图像。这个主题涵盖了多个相关知识点,包括
条形码
的基本原理、
PHP
生成
条形码
的方法以及常用的
PHP
条形码
类库。 首先,理解
条形码
的原理至关...
PHP
20,396
社区成员
19,657
社区内容
发帖
与我相关
我的任务
PHP
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
复制链接
扫一扫
分享
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
php
phpstorm
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章