chillerlan / php-qrcode

A PHP QR Code generator and reader with a user-friendly API.
https://smiley.codes/qrcode/
Apache License 2.0
2k stars 297 forks source link

Every image gives "could not find enough finder patterns." error #221

Closed mrl22 closed 11 months ago

mrl22 commented 1 year ago

Hello

I am hoping someone can point me in the right direction. Every time I am scanning an image, I get an error "could not find enough finder patterns." when calling ->readFromBlob();

I am scanning the image through the phone's camera in the browser at 800x600 resolution jpeg. This is sent to PHP as a Data-URI ($value), which I then decode and process through QRCode().

If I save the image data ($imageData) to a file, it displays correctly on my Mac.

I am running the dev-main branch.

Here is my code:

public function scan($value)
    {
        try {
            $parts = explode(',', $value, 2);
            if (count($parts) === 2) {
                $data = $parts[1];

                // Decode the Base64 data
                $imageData = base64_decode($data);

                // Check if the decoding was successful
                if ($imageData !== false) {
                    // Read the QR code
                    $this->scan = (new QRCode())->readFromBlob($imageData);

                } else {
                    throw new \Exception('Failed to decode the Data URI.');
                }
            } else {
                throw new \Exception('Invalid Data URI format.');
            }
        } catch (\Throwable $e) {
            $this->scan = $e->getMessage();
        }
    }
codemasher commented 1 year ago

Hi, do you have a sample image that produces the error? I'm not an expert in QR Code decoding/reading - the included reader is basically a cleaned-up fork of khanamiryan/php-qrcode-detector-decoder, which in turn is a port from the java source of the zxing project that comes with some limitations. So first you may want to check out if the original php port behaves similar, in which case it's an issue imported from there.

codemasher commented 11 months ago

I'm closing this due to the lack of feedback.