新聞中心
本篇內(nèi)容介紹了“php如何生成不同的條形碼”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
網(wǎng)站建設(shè)、成都網(wǎng)站制作介紹好的網(wǎng)站是理念、設(shè)計(jì)和技術(shù)的結(jié)合。創(chuàng)新互聯(lián)公司擁有的網(wǎng)站設(shè)計(jì)理念、多方位的設(shè)計(jì)風(fēng)格、經(jīng)驗(yàn)豐富的設(shè)計(jì)團(tuán)隊(duì)。提供PC端+手機(jī)端網(wǎng)站建設(shè),用營銷思維進(jìn)行網(wǎng)站設(shè)計(jì)、采用先進(jìn)技術(shù)開源代碼、注重用戶體驗(yàn)與SEO基礎(chǔ),將技術(shù)與創(chuàng)意整合到網(wǎng)站之中,以契合客戶的方式做到創(chuàng)意性的視覺化效果。
php生成不同的條形碼的方法:1、通過“composer require codeitnowin/barcode”語句安裝所需的代碼庫;2、將數(shù)據(jù)流文件寫入創(chuàng)建的文件內(nèi)容中;3、輸出圖片文件即可。
php 生成條形碼:
條形碼(barcode)是將寬度不等的多個(gè)黑條和空白,按照一定的編碼規(guī)則排列,用以表達(dá)一組信息的圖形標(biāo)識(shí)符。
這里采用php實(shí)現(xiàn),支持大多數(shù)的碼制。
條碼長(zhǎng)度
Code128,Code39 Extended, Code93 Extended 支持全全ASCII碼。
Code128有A、B、C三種字符集,每種字符集支持一部分,大致是這樣的,
A字符集支持支持AZ 26個(gè)大寫字母、09 9個(gè)數(shù)字及一些特殊字符;
B字符集支持支持AZ 26個(gè)大小寫字母、09 9個(gè)數(shù)字及一些特殊字符;
C字符集支持純數(shù)字字符,支持0`9 9個(gè)數(shù)字,而且是偶數(shù),如果是奇數(shù),生成條碼時(shí)自動(dòng)在前面加0;最大長(zhǎng)度純字符為32位,純字符加特殊符號(hào)炎44位。EAN/UCC 128 同 Code 128.
CODE128碼是廣泛應(yīng)用在企業(yè)內(nèi)部管理、生產(chǎn)流程、物流控制系統(tǒng)方面的條碼碼制,由于其優(yōu)良的特性在管理信息系統(tǒng)的設(shè)計(jì)中被廣泛使用,CODE128碼是應(yīng)用最廣泛的條碼碼制之一。
CODE128碼是1981年引入的一種高密度條碼,CODE128 碼可表示從 ASCII 0 到ASCII 127 共128個(gè)字符,故稱128碼。其中包含了數(shù)字、字母和符號(hào)字符。
Code 128碼與Code 39碼有很多的相近性,都廣泛運(yùn)用在企業(yè)內(nèi)部管理、生產(chǎn)流程、物流控制系統(tǒng)方面。不同的在于Code 128比Code 39能表現(xiàn)更多的字符,單位長(zhǎng)度里的編碼密度更高。當(dāng)單位長(zhǎng)度里不能容下Code 39編碼或編碼字符超出了Code 39的限制時(shí),就可選擇Code 128來編碼。
Code39,Code93支持的范圍為09數(shù)字字符及AZ 大寫字母和‘/’,‘+’,‘%’,‘$’,‘-’,‘.’及空格,長(zhǎng)度理論上沒有限制。
Code39 Extended, Code93 Extended 不支持‘-’,‘.’,其它和39 93一樣。
EAN8,EAN13,EAN Ext,UPC A,UPC E,UPC Ext支持的范圍為0`9數(shù)字字符,EAN8長(zhǎng)度為8,EAN13長(zhǎng)度為13,EAN8 Ext長(zhǎng)度為10或者13,EAN13 Ext長(zhǎng)度為15或者18,UPCA長(zhǎng)度為12,UPCE長(zhǎng)度為8,UPCE Ext長(zhǎng)度為10或者13,UPCA Ext長(zhǎng)度為14或者17。
Bookland,ISSN,ISSN可能支持?jǐn)?shù)字以外的其它字符,本中間件支持請(qǐng)參考“關(guān)于Bookland(ISBN)和ISSN”部分的說明。
Code11 支持的范圍為0`9數(shù)字字符及‘-’,長(zhǎng)度理論上沒有限制。
Codabar支持的范圍為0`9數(shù)字字符及‘A’,‘B’,‘C’,‘D’,‘-’,‘.’,‘/’,‘:’,‘+’,‘$’,開始和結(jié)尾字符必須是‘A’,‘B’,‘C’,‘D’中的字符,長(zhǎng)度理論上沒有限制。
MSI,Code 2of5 支持的范圍為0`9數(shù)字字符,長(zhǎng)度理論上沒有限制。
PostNet支持的范圍為0`9數(shù)字字符,長(zhǎng)度為5位,9位,或者11位,本開發(fā)包支持帶有非數(shù)字的格式,如12345-8012,使用更方便。
Matrix 25 (矩陣25碼) 支持的范圍為0`9數(shù)字字符,長(zhǎng)度為13位。
安裝所需的代碼庫
composer require codeitnowin/barcode
相關(guān)代碼(具體展示在后面)
Example - QrCode
'; echo '
Example - Code128
'; $barcode = new BarcodeGenerator(); $barcode->setText("0123456789"); $barcode->setType(BarcodeGenerator::Code128); $barcode->setScale(2); $barcode->setThickness(25); $barcode->setFontSize(10); $code = $barcode->generate(); echo ''; echo '
Example - Code11
'; $barcode = new BarcodeGenerator(); $barcode->setText("0123456789"); $barcode->setType(BarcodeGenerator::Code11); $code = $barcode->generate(); echo ''; echo '
Example - Code39
'; $barcode = new BarcodeGenerator(); $barcode->setText("0123456789"); $barcode->setType(BarcodeGenerator::Code39); $code = $barcode->generate(); echo ''; echo '
Example - Code39Extended
'; $barcode = new BarcodeGenerator(); $barcode->setText("0123456789"); $barcode->setType(BarcodeGenerator::Code39Extended); $code = $barcode->generate(); echo ''; echo '
Example - Ean128
'; $barcode = new BarcodeGenerator(); $barcode->setText("00123456789012345675"); $barcode->setType(BarcodeGenerator::Ean128); $code = $barcode->generate(); echo ''; echo '
Example - Gs1128
'; $barcode = new BarcodeGenerator(); $barcode->setText("00123456789012345675"); $barcode->setType(BarcodeGenerator::Gs1128); $code = $barcode->generate(); echo ''; echo '
Example - Gs1128
'; $barcode = new BarcodeGenerator(); $barcode->setText("4157707266014651802001012603068039000000006377069620171215"); $barcode->setType(BarcodeGenerator::Gs1128); $barcode->setNoLengthLimit(true); $barcode->setAllowsUnknownIdentifier(true); $code = $barcode->generate(); echo ''; echo '
Example - I25
'; $barcode = new BarcodeGenerator(); $barcode->setText("00123456789012345675"); $barcode->setType(BarcodeGenerator::I25); $code = $barcode->generate(); echo ''; echo '
Example - Isbn
'; $barcode = new BarcodeGenerator(); $barcode->setText("0012345678901"); $barcode->setType(BarcodeGenerator::Isbn); $code = $barcode->generate(); echo ''; echo '
Example - Msi
'; $barcode = new BarcodeGenerator(); $barcode->setText("0012345678901"); $barcode->setType(BarcodeGenerator::Msi); $code = $barcode->generate(); echo ''; echo '
Example - Postnet
'; $barcode = new BarcodeGenerator(); $barcode->setText("01234567890"); $barcode->setType(BarcodeGenerator::Postnet); $code = $barcode->generate(); echo ''; echo '
Example - S25
'; $barcode = new BarcodeGenerator(); $barcode->setText("012345678901"); $barcode->setType(BarcodeGenerator::S25); $code = $barcode->generate(); echo ''; echo '
Example - Upca
'; $barcode = new BarcodeGenerator(); $barcode->setText("012345678901"); $barcode->setType(BarcodeGenerator::Upca); $code = $barcode->generate(); echo ''; echo '
Example - Upce
'; $barcode = new BarcodeGenerator(); $barcode->setText("012345"); $barcode->setType(BarcodeGenerator::Upce); $code = $barcode->generate(); echo 'base64格式的圖片數(shù)據(jù)如何轉(zhuǎn)成圖片
// $base_img是獲取到前端傳遞的值
$base_img = str_replace('data:image/jpg;base64,', '', $code);
// 設(shè)置文件路徑和命名文件名稱
$path = "D:/Uploads/Bar/2019-12-11/";
$output_file = time().rand(100,999).'.jpg';
$path = $path.$output_file;
// 創(chuàng)建將數(shù)據(jù)流文件寫入我們創(chuàng)建的文件內(nèi)容中
file_put_contents($path, base64_decode($base_img));
// 輸出文件
print_r($output_file);
Buy me a cup of coffee :)
“php如何生成不同的條形碼”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
網(wǎng)站題目:php如何生成不同的條形碼
分享地址:http://fisionsoft.com.cn/article/iheddh.html