orlyapps/zbar-qrdecoder

PHP 对 Zbar 的封装。用于解码包含二维码的图片/照片。

3.0.4 2019-02-28 14:12 UTC

This package is auto-updated.

Last update: 2024-08-29 05:00:29 UTC


README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

这是 zbar-tools 的 PHP 封装 - 目前只包括 zbarimg。请参阅 http://zbar.sourceforge.net/

要求

  • zbar-tools - 在 Ubuntu 上安装非常简单,只需 sudo apt-get install zbar-tools。更多平台的信息请参见他们的 项目页面
  • ImageMagick - Zbar 需要,我不确定他们是否捆绑了它,所以请确保您已经安装了它

安装

通过 Composer 安装此包。

将此添加到您的 composer.json 依赖项中

"require": {
   "orlyapps/zbar-qrdecoder": "^2.0"
}

运行 composer install 下载所需文件。

用法

require_once('vendor/autoload.php');

$ZbarDecoder = new RobbieP\ZbarQrdecoder\ZbarDecoder();

# Optionally change the path of the zbarimg executable if you need to (default: /usr/bin)
$ZbarDecoder->setPath('/usr/local/bin');

# Decode the image
$result = $ZbarDecoder->make('/a/path/to/image_with_barcode.jpg');

echo $result; // Outputs the decoded text
echo $result->getFormat(); // Outputs the barcode's format
echo $result->getText(); // 200 if it decoded a barcode OR 400 if it couldn't find a barcode.

如果您在 Laravel 中使用它...

如果您需要更改任何选项,我已包括一个 ServiceProvider 类和一个配置文件。您需要将 ServiceProvider 添加到 config/app.php

'providers' => array(
    ...
    'RobbieP\ZbarQrdecoder\ZbarQrdecoderServiceProvider'
)

您可能需要发布配置 php artisan vendor:publish

现在您可以在 Laravel 应用程序中使用 Zbar QR Decoder 了!

用法(在 Laravel 中)

# Decode the image
$result = ZbarDecoder::make('/a/path/to/image_with_barcode.png');

echo $result; // Outputs the decoded text
echo $result->format; // Outputs the barcode's format

支持的其它条码

  • EAN_13 / ISBN
  • CODE_39
  • CODE_128

贡献

  1. 分支
  2. 创建您的功能分支: git checkout -b my-new-feature
  3. 提交您的更改: git commit -am '添加某些功能'
  4. 推送到分支: git push origin my-new-feature
  5. 提交 pull request