mindongji/php-zxing
Composer 安装命令:
composer require mindongji/php-zxing
包简介
Wrapper for zxing using php
README 文档
README
PHPZxing is a small php wrapper that uses the Zxing library to Create and read Barcodes. Under the hood it still uses the Zxing library to encode and decode data.
Install using composer
{
"require": {
"mindongji/php-zxing": "1.0.1"
}
}
Note
- Only Decoder is programmed right now. Needs programming of Encoder.
- The Default location of java that is configured is /usr/bin/java
Changes in version 1.0.1
- Added a isFound function that will tell if the bar code is found.
- If the image has one bar code detected, then it returns the object instead of array of a single object.
Basic Usage
use PHPZxing\PHPZxingDecoder; $decoder = new PHPZxingDecoder(); $data = $decoder->decode('../images/Code128Barcode.jpg'); if($data->isFound()) { $data->getImageValue(); $data->getFormat(); $data->getType(); }
The Decoded data is an Array of Objects of PHPZxing\ZxingImage if the bar code is found. If not found then it is an array of Objects PHPZxing\ZxingBarNotFound.
Checking for existence of Barcode
The Existance of bar code can be found using the functoin isFound()
use PHPZxing\PHPZxingDecoder; $decoder = new PHPZxingDecoder(); $data = $decoder->decode('../images/Code128Barcode.jpg'); if($data->isFound()) { $data->getImageValue(); $data->getFormat(); $data->getType(); }
You can also check using the instanceof object,
use PHPZxing\PHPZxingDecoder; $decoder = new PHPZxingDecoder(); $data = $decoder->decode('../images/Code128Barcode.jpg'); if($data instanceof PHPZxing\ZxingImage) { $data->getImageValue(); $data->getFormat(); $data->getType(); }
The Public methods that we can use in PHPZxing\ZxingImage are,
| Method Name | Function |
|---|---|
| getImageValue | Get the value decoded in the image passed |
| getFormat | Get the format of the image that is encoded, example : CODE_39 |
| getType | Get the type of the image decoded, example : URL, TEXT etc |
| getImagePath | Get Path of the image |
The Public methods that we can use in PHPZxing\ZxingImage are,
| Method Name | Function |
|---|---|
| getImageErrorCode | Get the error code for the image not found |
| getErrorMessage | Error Message |
| getImagePath | Get Path of the image |
Setting the configurations
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); } } }
You can also use it with configurations. The Decoder has 3 configurations,
| Config Name | Function |
|---|---|
| try_harder | If the image has bar/Qr code at unknown locations, then use this non mobile mode. |
| multiple_bar_codes | If the image has multiple bar codes you want to read. |
| crop | Crop the image and it will read only the cropped portion |
More Examples
You can pass array of images too,
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"; } }
Reading multiple bar codes,
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);
Set Java Path
If your java PATH is not set properly, the decoder will not work. You need to set path of java variable.
use PHPZxing\PHPZxingDecoder; $decoder = new PHPZxingDecoder(); $decoder->setJavaPath('/your/path/to/java'); $decodedData = $decoder->decode('../images/Code128Barcode.jpg'); print_r($decodedData);
Where is my java located ?
If you do not know the path to java, then you can use the following on *nix enviromnents
$ which java
On Windows read the follwoing stackoverflow Link
Acknowledgments
Contibution
Please Contribute or suggest changes.
mindongji/php-zxing 适用场景与选型建议
mindongji/php-zxing 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 395 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 11 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mindongji/php-zxing 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mindongji/php-zxing 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 395
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-11-01