1.安裝ImageMagick依賴
yum install ImageMagick ImageMagick-devel
2.安裝zbar拓展
wget -c http://jaist.dl.sourceforge.net/project/zbar/zbar/0.10/zbar-0.10.tar.bz2 tar jxvf zbar-0.10.tar.bz2 cd zbar-0.10 ./configure --without-gtk --without-python --without-qt --disable-video --prefix=/usr/local/zbar ##禁止gtk,python和qt的支持 make && make install
3.安裝php-zbarcode
//如果服務器沒有安裝git先使用 yum -y install git //安裝git git clone https://github.com/mkoppanen/php-zbarcode.git cd php-zbarcode /www/server/php/72/bin/phpize ./configure --with-php-config=/www/server/php/72/bin/php-config --with-zbarcode=/usr/local/zbar/ make && make install
4.添加extension=zbarcode.so 到php.ini中然后重啟
//創建一個img對象 $image = new ZBarCodeImage('4324.jpg'); // 創建一個二維碼識別器 $scanner = new ZBarCodeScanner(); //識別圖像 $barcode = $scanner->scan($image); echo json_encode($barcode);exit;