khanamiryan/qrcode-detector-decoder
Pure-PHP QR code detector/decoder (ported from ZXing). Reads QR codes from image files using GD, no extra extensions required. Simple API: create a Zxing\QrReader with a path and call text() to get the decoded content.
Begin by installing the package via Composer:
composer require khanamiryan/qrcode-detector-decoder
Then decode a QR code in minutes—no extension setup needed. In a Laravel controller:
use Zxing\QrReader;
public function decode(Request $request)
{
$path = $request->file('qr_image')->getRealPath();
$qrcode = new QrReader($path);
$text = $qrcode->text();
if ($text === false) {
return response()->json(['error' => 'QR code not readable'], 400);
}
return response()->json(['data' => $text]);
}
This handles common workflows like validating uploaded ticket images or scanning loyalty QR codes—ideal for server-side processing where client-side JS is impractical.
QRDecoderService) for clean DI in controllers/jobs:
class QRDecoderService
{
public function decode(string $path): ?string
{
$reader = new QrReader($path);
return $reader->text() ?: null;
}
}
ProcessInventoryScansJob that reads images from $storage->path('scans/*.jpg').$image = imagecreatefromjpeg($path);
$gray = imagefilter($image, IMG_FILTER_GRAYSCALE);
$binary = imagefilter($gray, IMG_FILTER_BRIGHTNESS, -30);
imagepng($binary, $tempPath = sys_get_temp_dir() . '/qr_prep.png');
$decoded = (new QrReader($tempPath))->text();
$reader = new QrReader($path, QrReader::SOURCE_TYPE_FILE, true);
$raw = $reader->text();
$payload = json_decode(mb_convert_encoding($raw, 'UTF-8', 'auto'), true);
php artisan tinker --execute='extension_loaded("gd")'. Docker users: add --with-gd or use official PHP images with GD enabled.QrReader throws RuntimeException if the file doesn’t exist—always validate Storage::disk('local')->exists($path) first.text() returns false on decode failure, not null. Use strict comparison: if ($text === false).$text = mb_convert_encoding($text ?? '', 'UTF-8', 'auto');
ini_set('memory_limit', '512M'); // Critical in queue workers
QrReader via constructor to mock in tests:
$mock = $this->createMock(QrReader::class);
$mock->method('text')->willReturn('test-data');
^2.0 for PHP 8.1–8.3 support. Version 1.x has critical PHP 8+ type errors. Check your composer.lock!How can I help you explore Laravel packages today?