php barcode_php 生成条形码(支持任意php框架)

一:插件安装

在php中我们可以使用php-barcode-generator插件来生成条形码,php-barcode-generator插件github地址:https://github.com/picqer/php...

composer require picqer/php-barcode-generator

二:php-barcode-generator插件简单使用

1:例:

$generator = new \Picqer\Barcode\BarcodeGeneratorHTML();

echo $generator->getBarcode('123456', $generator::TYPE_CODE_128);

根据如上就可以实现条形码的生成:

7d571f19ed1732f64b753f9ac5aec640.png

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中了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值