PHP code example of dsiddharth2 / php-zxing

1. Go to this page and download the library: Download dsiddharth2/php-zxing library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dsiddharth2 / php-zxing example snippets


use PHPZxing\PHPZxingDecoder;

$decoder        = new PHPZxingDecoder();
$data           = $decoder->decode('../images/Code128Barcode.jpg');
if($data->isFound()) {
    $data->getImageValue();
    $data->getFormat();
    $data->getType();        
}

use PHPZxing\PHPZxingDecoder;

$decoder        = new PHPZxingDecoder();
$data           = $decoder->decode('../images/Code128Barcode.jpg');
if($data->isFound()) {
    $data->getImageValue();
    $data->getFormat();
    $data->getType();        
}

use PHPZxing\PHPZxingDecoder;

$decoder        = new PHPZxingDecoder();
$data           = $decoder->decode('../images/Code128Barcode.jpg');
if($data instanceof PHPZxing\ZxingImage) {
    $data->getImageValue();
    $data->getFormat();
    $data->getType();
}

use PHPZxing\PHPZxingDecoder;

$config = array(
    'try_harder'            => true,
);
$decoder        = new PHPZxingDecoder($config);
$decodedArray   = $decoder->decode('../images');
if(is_array($decodedArray)){
    foreach ($decodedArray as $data) {
        if($data->isFound()) {
            print_r($data);
        }
    }
}

use PHPZxing\PHPZxingDecoder;

$decoder        = new PHPZxingDecoder();
$imageArrays = array(
    '../images/Code128Barcode.jpg',
    '../images/Code39Barcode.jpg'
);
$decodedArray  = $decoder->decode($imageArrays);
foreach ($decodedArray as $data) {
    if($data instanceof PHPZxing\ZxingImage) {
        print_r($data);
    } else {
        echo "Bar Code cannot be read";
    }
}

use PHPZxing\PHPZxingDecoder;

$config = array(
    'try_harder' => true,
    'multiple_bar_codes' => true
);
$decoder        = new PHPZxingDecoder($config);
$decodedData    = $decoder->decode('../images/multiple_bar_codes.jpg');
print_r($decodedData);

use PHPZxing\PHPZxingDecoder;

$decoder        = new PHPZxingDecoder();
$decoder->setJavaPath('/your/path/to/java');
$decodedData    = $decoder->decode('../images/Code128Barcode.jpg');
print_r($decodedData);