php如何利用barcode
生成不同类型的条形码,下面编程教程网小编给大家详细介绍一下如何实现!
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 :)
以上是编程学习网小编为您介绍的“php如何生成不同类型的条形码”的全面内容,想了解更多关于 php入门 内容,请继续关注编程基础学习网。
沃梦达教程
本文标题为:php如何生成不同类型的条形码
基础教程推荐
猜你喜欢
- php利用函数提取数组中不重复的值 2024-12-04
- php实现不用数据库实现在线短消息收发的代码 2022-08-27
- php获取数组最大值和最小值及求差 2024-12-04
- php如何去掉二维数组中的key 2024-12-04
- php可以利用for循环来实现阶乘算法吗? 2024-12-04
- php如何解决符号乱码问题 2024-12-05
- php数组可以返回指定元素的三种方法 2024-12-04
- phpword读取内容和样式 生成新的内容 2022-09-23
- php利用api接口做一个发送短信功能 2024-12-05
- php有哪些输出数组的函数 2024-12-04