安装PHP拓展 php-zbar 0.10
super
2021-09-19 12:09

- 1. 安装imageMagick
2. 安装zbar
下载
wget http://downloads.sourceforge.net/project/zbar/zbar/0.10/zbar-0.10.tar.gz
解压
tar -zvxf zbar-0.10.tar.gz
cd zbar-0.10
./configure --disable-video --without-gtk --without-python --without-qt --prefix=/usr/local/zbar

make && make install
安装完成

ldconfig
建立软链
ln -s /usr/local/zbar/lib/pkgconfig/zbar.pc /usr/lib64/pkgconfig/zbar.pc
3. 安装php拓展
wget https://codeload.github.com/mkoppanen/php-zbarcode/zip/refs/heads/master
unzip master

cd php-zbarcode-master/
找到你的 PHP 安装位置

[root@192 php-zbarcode-master]# /www/server/php/71/bin/phpize
Configuring for:
PHP Api Version: 20160303
Zend Module Api No: 20160303
Zend Extension Api No: 320160303
[root@192 php-zbarcode-master]# ./configure --with-php-config=/www/server/php/71/bin/php-config

make && make install

====================
如果报错了 error: too many arguments to function ‘zbar_version

进这个文件修改834行,删掉高亮的内容后重新make

====================
安装完成,进入目录下查看拓展.so文件

将拓展添加进php.ini文件

extension=zbarcode.so
保存文件并重启php-fpm
打开PHPINFO搜索 zbar

测试:

// 创建图片对象
$image = new ZBarCodeImage("./qrcode.png");
// 开始扫描
$barcode = (new ZBarCodeScanner())->scan($image);
if ($barcode) {
print_r($barcode);
exit;
}
echo "Sorry, 解析失败!";

1 条讨论