php 生成条码插件,php 生成条形码(支持任意php框架)
您现在的位置是:网站首页>>PHP>>phpphp 生成条形码(支持任意php框架)发布时间:2019-11-29 11:53:51作者:wangjian浏览量:689点赞量:0一:插件安装在php中我们可以使用php-barcode-generator插件来生成条形码,php-barcode-generator插件github地址:https://github.com/p
您现在的位置是:网站首页>>PHP>>php
php 生成条形码(支持任意php框架)
发布时间:2019-11-29 11:53:51作者:wangjian浏览量:689点赞量:0
一:插件安装
在php中我们可以使用php-barcode-generator插件来生成条形码,php-barcode-generator插件github地址:https://github.com/picqer/php-barcode-generatorcomposer require picqer/php-barcode-generator
二:php-barcode-generator插件简单使用
1:例:$generator = new \Picqer\Barcode\BarcodeGeneratorHTML();
echo $generator->getBarcode('123456', $generator::TYPE_CODE_128);
根据如上就可以实现条形码的生成:

2:根据条形码生成类型,我们可以使用如下四种方式生成条形码$generatorSVG = new \Picqer\Barcode\BarcodeGeneratorSVG(); #创建SVG类型条形码
$generatorPNG = new \Picqer\Barcode\BarcodeGeneratorPNG(); #创建PNG类型条形码
$generatorJPG = new \Picqer\Barcode\BarcodeGeneratorJPG(); #创建JPG类型条形码
$generatorHTML = new \Picqer\Barcode\BarcodeGeneratorHTML(); #创建HTML类型条形码
如果要生成PNG或JPG图像,则还需要在系统上安装GD库或Imagick拓展,Imagick拓展安装方式可参考:PHP的Imagick拓展安装
3:getBarcode方法参数说明:getBarcode($code, $type, $widthFactor = 2, $totalHeight = 30, $color = 'black')
code:条形码数据
type:条形码的类型,使用在类中定义的常量,具体参数可参考github
widthFactor:条形码的宽度
totalHeight:条形码高度
color:条形码的颜色
4:如果你想要将条形码嵌入到html中
将生成的条形码进行base64编码嵌入到img标签中$generator = new \Picqer\Barcode\BarcodeGeneratorPNG();
$barcode = $generator->getBarcode('123456', $generator::TYPE_CODE_128);
$barcode = base64_encode($barcode);
echo ' ';
这样就可以将条形码嵌入到html中了

0
+1
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)