php生成條形碼的圖片的實(shí)例詳解
成都創(chuàng)新互聯(lián)主要從事成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)回民,十多年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):13518219792
因?yàn)橛脩舻男枰?/p>
寫了一個(gè)條形碼;用php生成一個(gè)條形碼的圖片
這個(gè)大家應(yīng)該比我要好很多的吧,在自己項(xiàng)目的根目錄下建立一個(gè)測(cè)試文件(直接把下面的代碼放進(jìn)去運(yùn)行一下看看,我也是抄襲別人的),在實(shí)際的項(xiàng)目中你可以將下面的代碼封裝到一個(gè)公共類文件下的一個(gè)函數(shù),然后調(diào)用。
class
testinfo{
function
UPCAbarcode($code)
{
$trans_code
=
$code;
$lw
=
2.2;
$hi
=
40;
$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';
/*
Compute
the
EAN-13
Checksum
digit
*/
$ncode
=
'0'.$code;
$even
=
0;
$odd
=
0;
for
($x=0;$x12;$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;$x6;$x++)
{
$bars.=$Lencode[$code[$x]];
}
$bars.=$center;
for($x=6;$x12;$x++)
{
$bars.=$Rencode[$code[$x]];
}
$bars.=$ends;
/*
Generate
the
Barcode
Image
*/
$img
=
ImageCreate($lw*75+30,$hi-3);
//
95
$fg
=
ImageColorAllocate($img,
0,
0,
0);
$bg
=
ImageColorAllocate($img,
255,
255,
255);
ImageFilledRectangle($img,
0,
0,
$lw*75+30,
$hi+30,
$bg);
$shift=10;
for
($x=0;$xstrlen($bars);$x++)
{
if
(($x0)
||
($x=45
$x46)
||
($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;$x5;$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-7,$hi,$code[11],$fg);
/*
Output
the
Header
and
Content.
*/
header("Content-Type:
image/png");
ImagePNG($img);
}
//}
echo
UPCAbarcode('201212070099');
如有疑問請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
如果條碼采集器沒有損壞的話,你掃描的東西的條碼一定是掃過第二次的時(shí)候才報(bào)的重復(fù),你只需要?jiǎng)h除當(dāng)前掃描的條碼數(shù)據(jù)即可。如果一直報(bào)重復(fù),無法繼續(xù)掃描的情況,那就是程序損壞了,更壞程序,重裝一下。
Header("Content-type: image/jpeg");//設(shè)置文件頭
$im = imagecreatefromjpeg("D:\1.jpg");//返回一圖像標(biāo)識(shí)符,代表了從給定的文件名取得的圖像。
Imagejpeg($im,'',20);//輸出到瀏覽器
ImageDestroy($im);//銷毀
試試這個(gè)行不行。
你可以弄一個(gè)顯示專門顯示
數(shù)組
的,最后結(jié)束了做一個(gè)寫入excel表格處理,那你的數(shù)組數(shù)據(jù)都存excel里了,以后你隨便要用origin啊什么
軟件
來處理導(dǎo)入就很方便了
?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;$x12;$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;$x6;$x++)
{
$bars.=$Lencode[$code[$x]];
}
$bars.=$center;
for($x=6;$x12;$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;$xstrlen($bars);$x++) {
if (($x10) || ($x=45
$x50) || ($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;$x5;$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('12345678901');
?
分享名稱:條形碼數(shù)據(jù)采集器php 采樣條形碼
新聞來源:http://chinadenli.net/article0/dodieoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、外貿(mào)網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站、全網(wǎng)營(yíng)銷推廣、品牌網(wǎng)站建設(shè)、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)