php-qrcode-detector-decoder: Wrong result

This file can not be decoded with QrReader! it just returns (bool)false. But the text encoded in the QR Code is w_537244_40.

$QrReader = new QrReader('wrong.png');
echo $QrReader->text();

wrong

The correct result can be proved with the online Zxing.org encoder here. It returns:

Raw text              w_537244_40
Raw bytes             40 27 75 f1 01 a1 93 d1   00 d7 cd 0c 00 ec 11 ec
Barcode format        QR_CODE
Parsed Result Type    TEXT
Parsed Result         w_537244_40

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 2
  • Comments: 25 (3 by maintainers)

Most upvoted comments

To fix my issue like as your issue, I used imagecopyresampled For example you can see my code:

$width = imagesx($imageResource);
$height = imagesy($imageResource);

for ($zoom = 100; $zoom >= 10; $zoom -= 10) {
    $new_width = $width * $zoom / 100;
    $new_height = $height * $zoom / 100;
    $zoomResource = imagecreate(800, 350);

    imagecopyresampled(
        $zoomResource,
        $imageResource,
        0,
        0,
        0,
        0,
        $new_width,
        $new_height,
        $width,
        $height
    );

    imagepng($zoomResource, $pathTempPng, 0, PNG_NO_FILTER);
    imagedestroy($zoomResource);

    try {
        $qrcode = new QrReader($pathTempPng);
        $numText = $qrcode->text();
        if ($numText) {
            echo ' FIND ' . $numText . ', ';
            break;
        }
    } catch (\InvalidArgumentException $e) {
        $numText = null;
    }

    echo '{' . $zoom . ' | ' . $numText . ' }, ';
}

The percentage of detected QRcodes increased from 10% to 90% for me.

To fix my issue like as your issue, I used imagecopyresampled For example you can see my code:

$width = imagesx($imageResource);
$height = imagesy($imageResource);

for ($zoom = 100; $zoom >= 10; $zoom -= 10) {
    $new_width = $width * $zoom / 100;
    $new_height = $height * $zoom / 100;
    $zoomResource = imagecreate(800, 350);

    imagecopyresampled(
        $zoomResource,
        $imageResource,
        0,
        0,
        0,
        0,
        $new_width,
        $new_height,
        $width,
        $height
    );

    imagepng($zoomResource, $pathTempPng, 0, PNG_NO_FILTER);
    imagedestroy($zoomResource);

    try {
        $qrcode = new QrReader($pathTempPng);
        $numText = $qrcode->text();
        if ($numText) {
            echo ' FIND ' . $numText . ', ';
            break;
        }
    } catch (\InvalidArgumentException $e) {
        $numText = null;
    }

    echo '{' . $zoom . ' | ' . $numText . ' }, ';
}

The percentage of detected QRcodes increased from 10% to 90% for me.

Your solution saved my day! Thanks a bunch ❤️

@shoaib-sme in my code. After the try

$qrcode = new QrReader($pathImage);
$numText = $qrcode->text();

if ($numText == null) {
 // this
}

To fix my issue like as your issue, I used composer require topthink/think-image For example you can see my code:

...
$file_path = $dir_path . '/upload.png';
$image = Image::open($file_path);
$qrReaderPath = $dir_path . '/qrReader.png';
$image->thumb(150, 150)->save($qrReaderPath);
$qrcode = new QrReader($qrReaderPath);
if (!$qrcode->text()) {
    return 'error';
}
return 'success';