james2001 / zxing-bundle
Symfony bundle to read QR codes and barcodes from images with ZXing
Package info
github.com/james2001/zxingbundle
Type:symfony-bundle
pkg:composer/james2001/zxing-bundle
Requires
- php: >=8.1
- james2001/zxing: ^2.0
- symfony/config: ^6.4 || ^7.0 || ^8.0
- symfony/dependency-injection: ^6.4 || ^7.0 || ^8.0
- symfony/http-kernel: ^6.4 || ^7.0 || ^8.0
Requires (Dev)
- phpunit/phpunit: ^10.5.62 || ^11.5.50 || ^12.5.8
- symfony/framework-bundle: ^6.4 || ^7.0 || ^8.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Symfony bundle to read QR codes and barcodes from images, with the james2001/zxing library (a PHP wrapper around the Java ZXing reader).
Which version should I use?
| Bundle | Branch | PHP | Symfony | Library |
|---|---|---|---|---|
| 3.x | 3.x |
8.1+ | 6.4, 7.x, 8.x | james2001/zxing 2.x |
| 2.x | 2.x |
7.2.5 – 8.x | 4.4, 5.4 | james2001/zxing 1.x/2.x |
| 1.x | 1.x |
5.4 – 7.4 | 2.3 – 3.4 | james2001/zxing 1.x |
composer require james2001/zxing-bundle installs the newest version compatible
with your PHP and Symfony versions.
This branch (3.x) is the active one, for Symfony 6.4, 7.x and 8.x applications.
Requirements
Java 8 or later must be installed on the server: the java command has to be in
the PATH.
Installation
composer require james2001/zxing-bundle
With Symfony Flex the bundle is enabled automatically. Otherwise add it to
config/bundles.php:
return [ // ... James2001\Bundle\ZxingBundle\James2001ZxingBundle::class => ['all' => true], ];
Configuration
Everything is optional, for instance in config/packages/james2001_zxing.yaml:
james2001_zxing: key: '' # only keep codes containing this key (removed from the result) options: [] # extra ZXing options, e.g. ['--try_harder'] (a string such as '--try_harder' works too) lib_bin_path: '' # directory holding the ZXing jars (defaults to the bundled ones)
options is passed to the ZXing command line (without any shell): never fill it
with user input. The available options are listed in the
james2001/zxing README.
Usage
use James2001\Zxing; class ScanController extends AbstractController { public function scan(Zxing $zxing): Response { $first = $zxing->findFirst('/path/image.jpg'); // string, or false if nothing is found $all = $zxing->findMulti('/path/image.jpg'); // array of strings, or false // ... } }
The reader is also available as the public james2001.zxing service.
Upgrading from 2.x
- PHP 8.1 and Symfony 6.4 are the new minimums, and
james2001/zxing2.x is required: it ships ZXing 3.5, which needs Java 8 and spells some options differently (--possible_formats QR_CODEinstead of--possibleFormats=QR_CODE). See its upgrade notes. optionscan now be a list; a string is split on spaces.- The bundle class is now an
AbstractBundleand isfinal: theDependencyInjectionclasses are gone. Thejames2001_zxingconfiguration key, thejames2001.zxingservice and theZxingautowiring alias don't change.
Upgrading from 1.x
Apply these changes, then the ones of "Upgrading from 2.x" above:
- The
james2001_zxing.key,james2001_zxing.options,james2001_zxing.libBinPathandjames2001_zxing.classparameters are replaced by thejames2001_zxingconfiguration key shown above (libBinPathbecomeslib_bin_path). - The sources moved to
src/andResources/config/services.ymlis gone: the service is declared by the extension. The service idjames2001.zxingdoesn't change.
Tests
composer install vendor/bin/phpunit
License
MIT, see LICENSE.