1. 程式人生 > >PHP識別二維碼(php-zbarcode)

PHP識別二維碼(php-zbarcode)

說明:擴充套件需要依賴ImageMagick和zbar,安裝前先安裝這兩個軟體 yum install ImageMagick.x86_64 ImageMagick-devel.x86_64 tar jxvf zbar-0.10.tar.bz2
cd zbar-0.10 #注意此步有大坑,要禁止gtk,python和qt的支援,不然你就等著無限報錯吧 ./configure --without-gtk --without-python --without-qt --prefix=/usr/local/zbar make && make install
#提示如下為完成,不是報錯 #make[2]: Leaving directory `/root/zbar-0.10' #make[1]: Leaving directory `/root/zbar-0.10' #echo “/usr/local/zbar/lib/” >> /etc/ld.so.conf  ldconfig  ln -s /usr/local/zbar/lib/pkgconfig/zbar.pc  /usr/lib64/pkgconfig/zbar.pc unzip php-zbarcode-master.zip  cd php-zbarcode-master /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config make && make install
#提示如下完成 #Build complete. #Don't forget to run 'make test'. #Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/ 4.新增:extension=zbarcode.so 到php.ini配置檔案 此時檢視phpinfo();後搜尋zbarcode後為完成 5.測試效果   圖片取自https://en.wikipedia.org/wiki/File:Ean-13-5901234123457.png
<?php
	//新建一個影象物件
	$image = new ZBarCodeImage("./test.png");

	// 建立一個二維碼識別器
	$scanner = new ZBarCodeScanner();

	//識別影象
	$barcode = $scanner->scan($image);

	//迴圈輸出二維碼資訊
	if (!empty($barcode)) {
	    foreach ($barcode as $code) {
	        printf("Found type %s barcode with data %s\n", $code['type'], $code['data']);
	    }
	}
?>