← All open source 04 · PHP · MIT

PHP ZXing.

PHP wrapper for the ZXing barcode library

Composer wrapper around ZXing so PHP apps can read barcodes and QR codes.

Published on Packagist 277K+ installs
$ composer require dsiddharth2/php-zxing
dsiddharth2/php-zxing ↗ (opens in a new tab)
$ git clone https://github.com/dsiddharth2/php-zxing

Composer package for reading barcodes and QR codes. 277K+ Packagist installs, 133 GitHub stars, and featured on the upstream ZXing repo.

Built with PHPComposerZXingJava
277K+Packagist installs
133GitHub stars
Featuredon ZXing repo
MITopen source

Problem

  • PHP had no solid barcode decoder of its own
  • ZXing lived in Java, unusable from Composer apps
  • Teams were shelling out to one-off scripts
  • No typed result for found versus not-found
  • Windows and *nix Java paths differed every deploy
  • Multiple barcodes in one image were ignored

Solution

  • Composer package wrapping ZXing core.jar and javase.jar
  • Shell out to the local JRE with a stable PHP API
  • Decode a file, a directory, or an array of images
  • try_harder, crop, and possible_formats configs
  • Typed results: ZxingImage versus ZxingBarNotFound
  • Configurable Java path for *nix and Windows

Outcome

  • 277K+ Packagist installs across production PHP apps
  • 133 GitHub stars and ongoing community use
  • Featured on the primary ZXing GitHub repository
  • Single Composer require instead of custom Java glue
  • Multiple barcodes per image supported
  • MIT licensed and still the default PHP path to ZXing

How it works

  1. Install

    Composer pulls the PHP wrapper plus the bundled ZXing jars. A local JRE is the only runtime dependency outside PHP.

  2. Decode

    The wrapper shells out to Java with the configured path, passing try_harder, crop, format filters, and multi-barcode flags through to ZXing.

  3. Result

    Callers get a typed ZxingImage or ZxingBarNotFound. isFound() makes the success path obvious without parsing raw process output.

Key Decisions

  1. Wrap Java ZXing instead of rewriting a decoder in PHP

    Barcode decoding is a solved problem in ZXing. A thin, well-typed wrapper shipped in days; a PHP port would have been years of edge cases.

  2. Typed found / not-found results

    Shell output is messy. Returning ZxingImage versus ZxingBarNotFound made the API feel like PHP instead of like a process wrapper.

What I'd Change

  • A native PHP decoder path for hosts without Java Shared hosting often has no JRE. A pure-PHP fallback — even if slower — would have unlocked a large chunk of the install base.
  • Better Windows JRE discovery Configurable Java path works, but auto-detecting common Windows install locations would have cut the most frequent support issue.
Agent view
/opensource/php-zxing.md
Loading…