1

I am trying to use khanamiryan's php library for reading QR codes from image files; https://github.com/khanamiryan/php-qrcode-detector-decoder

Currently I am unable to get it working on Debian Stretch (specifically Raspbian Stretch on a Raspberry Pi 3B). I can only get HTTP 500 errors.

Clean install of Raspbian Stretch, then the following in a terminal;

sudo apt-get install apache2 php libapache2-mod-php php7.0-gd composer
cd /var/www/html
composer require khanamiryan/qrcode-detector-decoder

Here's the php I am trying to run;

<?php
require __DIR__ . "/vendor/autoload.php";
$qrcode = new QrReader('test.png');
$text = $qrcode->text();
print($text);
?>

Expected result is the text from the QR code in the image test.png is written to the response but I always get HTTP 500 error.

Any suggestions? Do I need to install some underlying C++ or Java library?

David Honess
  • 21
  • 1
  • 4
  • Have you checked the output of your web server log file (for apache2, generally at /var/log/apache2/error.log). In general you can found more information why the PHP script fails... – Ayak973 Apr 25 '19 at 12:08
  • Yes I'm getting this; Fatal error: Uncaught Error: Class 'QrReader' not found in /var/www/html/index.php:3 Stack trace: #0 {main} thrown in /var/www/html/index.php on line 3 – David Honess Apr 25 '19 at 12:21
  • Sounds like you need to add QrReader to the autoload, or possibly use the full namespace for the class name. – aynber Apr 25 '19 at 12:27
  • Aha, progress. I added the line `use Zxing\QrReader;` and now I have this error output (too long to fit in this comment) – David Honess Apr 25 '19 at 12:35
  • Use a backslash for namespace, i.e.: `use Zxing\QrReader;` – lovelace Apr 25 '19 at 12:38
  • Thanks yes I did use the backslash, here's the error output I am getting now - it looks like it's coming from within the library code https://pastebin.com/2FSzDZHM – David Honess Apr 25 '19 at 12:40
  • have a look at: [fatal error mb_detect_encoding](https://stackoverflow.com/questions/17204437/fatal-error-call-to-undefined-function-mb-detect-encoding) – lovelace Apr 25 '19 at 12:44
  • Lovelace, that was it - you're a legend. Thank you so much! o/ – David Honess Apr 25 '19 at 12:49

1 Answers1

0

Add namespace line use Zxing\QrReader;

<?php
use Zxing\QrReader;
require __DIR__ . "/vendor/autoload.php";
$qrcode = new QrReader('test.png');
$text = $qrcode->text();
print($text);
?>

Also run this in the terminal

sudo apt-get install php7.0-mbstring
David Honess
  • 21
  • 1
  • 4