之前作二維碼和條形碼都是直接用js的代碼生成,此次因特殊須要用php的,框架用的thinkphp,分別找到一個能夠composer的類庫,記錄下來。php
php二維碼的用Endroid\QrCodehtml
安裝方法:thinkphp
composer require endroid/qr-code
使用代碼composer
$qrCode = new \Endroid\QrCode\QrCode(); $url = 'http://www.test.test/id/10.html'; $qrCode->setText($url); $qrCode->setSize(300); $qrCode->setWriterByName('png'); $qrCode->setMargin(10); $qrCode->setEncoding('UTF-8'); $qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]); $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]); $qrCode->setLogoSize(150, 200); $qrCode->setRoundBlockSize(true); $qrCode->setValidateResult(false); $qrCode->setWriterOptions(['exclude_xml_declaration' => true]); // Directly output the QR code header('Content-Type: '.$qrCode->getContentType()); echo $qrCode->writeString();
php條形碼的用Milon\Barcode框架
安裝方法ui
composer require milon/barcode
使用代碼url
echo '<img style="width:188px;height:35px" src="data:image/png;base64,' . \Milon\Barcode\DNS1D::getBarcodePNG("test123456789", "C128",3,33) . '" alt="barcode" />';
也能夠用code
echo DNS1D::getBarcodeHTML("4445645656", "C39"); echo DNS1D::getBarcodeHTML("4445645656", "C39+"); echo DNS1D::getBarcodeHTML("4445645656", "C39E"); echo DNS1D::getBarcodeHTML("4445645656", "C39E+"); echo DNS1D::getBarcodeHTML("4445645656", "C93"); echo DNS1D::getBarcodeHTML("4445645656", "S25"); echo DNS1D::getBarcodeHTML("4445645656", "S25+"); echo DNS1D::getBarcodeHTML("4445645656", "I25"); echo DNS1D::getBarcodeHTML("4445645656", "I25+"); echo DNS1D::getBarcodeHTML("4445645656", "C128"); echo DNS1D::getBarcodeHTML("4445645656", "C128A"); echo DNS1D::getBarcodeHTML("4445645656", "C128B"); echo DNS1D::getBarcodeHTML("4445645656", "C128C"); echo DNS1D::getBarcodeHTML("44455656", "EAN2"); echo DNS1D::getBarcodeHTML("4445656", "EAN5"); echo DNS1D::getBarcodeHTML("4445", "EAN8"); echo DNS1D::getBarcodeHTML("4445", "EAN13"); echo DNS1D::getBarcodeHTML("4445645656", "UPCA"); echo DNS1D::getBarcodeHTML("4445645656", "UPCE"); echo DNS1D::getBarcodeHTML("4445645656", "MSI"); echo DNS1D::getBarcodeHTML("4445645656", "MSI+"); echo DNS1D::getBarcodeHTML("4445645656", "POSTNET"); echo DNS1D::getBarcodeHTML("4445645656", "PLANET"); echo DNS1D::getBarcodeHTML("4445645656", "RMS4CC"); echo DNS1D::getBarcodeHTML("4445645656", "KIX"); echo DNS1D::getBarcodeHTML("4445645656", "IMB"); echo DNS1D::getBarcodeHTML("4445645656", "CODABAR"); echo DNS1D::getBarcodeHTML("4445645656", "CODE11"); echo DNS1D::getBarcodeHTML("4445645656", "PHARMA"); echo DNS1D::getBarcodeHTML("4445645656", "PHARMA2T");