44

Is there a plain PHP implementation for decoding QR codes?

I have a faux-smartphone. One of those phones that parades as a smartphone but that I can't download any apps for, and I want to create an email service to where I can take a picture of a QR code, MMS it to this email, and the email returns what the QR code contains.

However, the only libraries I've been able to find are in Python (and probably C++), neither of which I can access on my limited hosting environment.

Is there a way to read QR codes using only PHP?

1
  • that is a really long way to go for qr-code reading!
    – Ajowi
    Commented Jun 28, 2020 at 11:06

3 Answers 3

39
+50

There is only one pure PHP QR code decoder. It's working with GD library, but can use also ImageMagick. This PHP QR code reader is ported from ZXing.

https://github.com/khanamiryan/php-qrcode-detector-decoder

2
  • I had always considered doing this myself but never found it worth the time tradeoff. You're amazing.
    – Navarr
    Commented Jun 28, 2015 at 20:14
  • 1
    @AshotKhanamiryan is there documentation available? I'm looking for debugging / error messages...
    – powtac
    Commented Feb 18, 2016 at 12:23
14

I'm not aware of any pure php decoder. Decoding images like this is pretty processor intensive and doing it in a purely interpreted language is challenging.

zxing (http://code.google.com/p/zxing/) provides a decoder implementation in both Java and C++. In theory, it should be possible to link the C++ library as a php extension, though I don't know anything of the mechanics of that. I've done it for Ruby ...

Moreover, zxing does have an online decoder at http://zxing.org/w/decode.jspx. My thinking is that from PHP you can take the image and post it to the webservice and retrieve the decoded data. I don't know the mechanics of making remote web service calls from PHP and how different hosting environments might limit that, though, but it seems reasonable?

2
  • Nice find with the zxing. I'm honestly looking into it and interpreting a QR Code in PHP, if possible, would be damned silly. Though PHP does have routines for checking the value of a bitmap pixel, it's very unintuitive and is generally used for averaging colors over and area or similar simple mathematical techniques, not finding patterns. Pattern matching would just be so complicated it's meaningless.
    – stevendesu
    Commented Oct 11, 2010 at 4:59
  • I'm sure I can find a way to utilize this with my PHP. Thanks a lot :) This is pretty much exactly what I was looking for in one way or another. :3
    – Navarr
    Commented Oct 11, 2010 at 21:41
10

If you have the possibility to use a phpextension, php-zbarcode at https://github.com/mkoppanen/php-zbarcode can read qrcodes. It's a wrapper for ZBar from http://zbar.sourceforge.net, which in turn is a LGPL C library for decoding barcodes.

2
  • Kudos. This is better than sending to ZXing.
    – Navarr
    Commented Aug 26, 2012 at 21:15
  • 2
    This wrapper seemed promising but now seems abandoned, isn't it ? Has anyone picked up the flame or succeded making it work ? Commented Oct 5, 2012 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.