rzani/zbar-qrdecoder

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

2.0.3 2018-05-16 13:49 UTC

This package is not auto-updated.

Last update: 2024-09-21 00:14:18 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": {
   "robbiep/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->format; // Outputs the barcode's format
echo $result->code; // 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. 提交拉取请求