2, 'scale' => 8, ]); $qrcode = new QRCode($options); Log::info('data encoded to QR code'); return $qrcode->render($data); } /** * Decode an uploaded QR code image * * @return string */ public static function decode(\Illuminate\Http\UploadedFile $file) { $qrcode = new QrReader($file->get(), QrReader::SOURCE_TYPE_BLOB); $text = $qrcode->text(); if (! $text) { $text = $qrcode->text([ 'TRY_HARDER' => true, 'NR_ALLOW_SKIP_ROWS' => 0, ]); } // At this point, if we do not have a text, QR code cannot be detected or decoded // so we check the error to provide the user a relevant error message if (! $text) { switch (get_class($qrcode->getError())) { case NotFoundException::class: throw new \App\Exceptions\InvalidQrCodeException(__('errors.cannot_detect_qrcode_in_image')); case FormatException::class: throw new \App\Exceptions\InvalidQrCodeException(__('errors.cannot_decode_detected_qrcode')); case ChecksumException::class: throw new \App\Exceptions\InvalidQrCodeException(__('errors.qrcode_has_invalid_checksum')); default: throw new \App\Exceptions\InvalidQrCodeException(__('errors.no_readable_qrcode')); } } $data = urldecode($qrcode->text()); Log::info('QR code decoded'); return $data; } }