php如何利用barcode
生成不同类型的条形码,下面web建站小编给大家详细介绍一下如何实现!
1、先安装代码库
composer require codeitnowin/barcode
2、介绍一下相关代码
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use CodeItNow\BarcodeBundle\Utils\BarcodeGenerator; use CodeItNow\BarcodeBundle\Utils\QrCode; class BarCodeController extends Controller { public function index() { echo '<p>Example - QrCode</p>'; $qrCode = new QrCode(); $qrCode ->setText('https://ipkd.cn') ->setSize(300) ->setPadding(10) ->setErrorCorrection('high') ->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0)) ->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0)) ->setLabel('https://ipkd.cn') ->setLabelFontSize(16) ->setImageType(QrCode::IMAGE_TYPE_PNG); echo '<img src="data:' . $qrCode->getContentType() . ';base64,' . $qrCode->generate() . '" />'; echo '<hr>'; echo '<p>Example - Code128</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("0123456789"); $barcode->setType(BarcodeGenerator::Code128); $barcode->setScale(2); $barcode->setThickness(25); $barcode->setFontSize(10); $code = $barcode->generate(); echo '<img src="https://ipkd.cn/images/logo.png' . $code . '" />'; echo '<hr>'; echo '<p>Example - Code11</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("0123456789"); $barcode->setType(BarcodeGenerator::Code11); $code = $barcode->generate(); echo '<img src="https://ipkd.cn/images/logo.png' . $code . '" />'; echo '<hr>'; echo '<p>Example - Code39</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("0123456789"); $barcode->setType(BarcodeGenerator::Code39); $code = $barcode->generate(); echo '<img src="https://ipkd.cn/images/logo.png' . $code . '" />'; echo '<hr>'; echo '<p>Example - Code39Extended</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("0123456789"); $barcode->setType(BarcodeGenerator::Code39Extended); $code = $barcode->generate(); echo '<img src="https://ipkd.cn/images/logo.png' . $code . '" />'; echo '<hr>'; echo '<p>Example - Ean128</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("00123456789012345675"); $barcode->setType(BarcodeGenerator::Ean128); $code = $barcode->generate(); echo '<img src="https://ipkd.cn/images/logo.png' . $code . '" />'; echo '<hr>'; echo '<p>Example - Gs1128</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("00123456789012345675"); $barcode->setType(BarcodeGenerator::Gs1128); $code = $barcode->generate(); echo '<img src="https://ipkd.cn/images/logo.png' . $code . '" />'; echo '<hr>'; echo '<p>Example - Gs1128</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("4157707266014651802001012603068039000000006377069620171215"); $barcode->setType(BarcodeGenerator::Gs1128); $barcode->setNoLengthLimit(true); $barcode->setAllowsUnknownIdentifier(true); $code = $barcode->generate(); echo '<img src="https://ipkd.cn/images/logo.png' . $code . '" />'; echo '<hr>'; echo '<p>Example - I25</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("00123456789012345675"); $barcode->setType(BarcodeGenerator::I25); $code = $barcode->generate(); echo '<img src="https://ipkd.cn/images/logo.png' . $code . '" />'; echo '<hr>'; echo '<p>Example - Isbn</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("0012345678901"); $barcode->setType(BarcodeGenerator::Isbn); $code = $barcode->generate(); echo '<img src="https://ipkd.cn/images/logo.png' . $code . '" />'; echo '<hr>'; echo '<p>Example - Msi</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("0012345678901"); $barcode->setType(BarcodeGenerator::Msi); $code = $barcode->generate(); echo '<img src="https://ipkd.cn/images/logo.png' . $code . '" />'; echo '<hr>'; echo '<p>Example - Postnet</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("01234567890"); $barcode->setType(BarcodeGenerator::Postnet); $code = $barcode->generate(); echo '<img src="https://ipkd.cn/images/logo.png' . $code . '" />'; echo '<hr>'; echo '<p>Example - S25</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("012345678901"); $barcode->setType(BarcodeGenerator::S25); $code = $barcode->generate(); echo '<img src="https://ipkd.cn/images/logo.png' . $code . '" />'; echo '<hr>'; echo '<p>Example - Upca</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("012345678901"); $barcode->setType(BarcodeGenerator::Upca); $code = $barcode->generate(); echo '<img src="https://ipkd.cn/images/logo.png' . $code . '" />'; echo '<hr>'; echo '<p>Example - Upce</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("012345"); $barcode->setType(BarcodeGenerator::Upce); $code = $barcode->generate(); echo '<img src="https://ipkd.cn/images/logo.png' . $code . '" />'; } }
3、base64格式的图片数据如何转成图片
$base_img = str_replace('data:image/jpg;base64,', '', $code); $path = "E:/Bar/2022-10-130/"; $output_file = time().rand(100,999).'.jpg'; $path = $path.$output_file; file_put_contents($path, base64_decode($base_img)); print_r($output_file); Buy me a cup of coffee :)
条形码报“JsBarcode No element to render on”错误解决方法
barcode条形码/qrcode二维码兼容所有浏览器(含ie6/ie7/ie8)
上面是“php如何生成不同类型的条形码”的全面内容,想了解更多关于 php入门 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_2607.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!