php-qrcode-detector-decoder icon indicating copy to clipboard operation
php-qrcode-detector-decoder copied to clipboard

QRcode not decoding getting blank response

Open KinjalDalsaniya opened this issue 5 years ago • 5 comments

I am trying to decode QR code image which is photo or screenshot taken from mobile phone/computer , but getting blank response. In short it is not working from any type of photo taken from Mobile/Computer.

Please resolve my issue ASAP.

Thanks in advance

KinjalDalsaniya avatar Apr 09 '19 12:04 KinjalDalsaniya

me too

kamalkech avatar Jul 04 '19 10:07 kamalkech

Same here. I'm generating the QR code with Google charts. When I try to upload that QR code it comes back with no data.

jlmweb avatar Jul 30 '19 18:07 jlmweb

The same. I tried to take a picture of a QrCode and it did not decode. Here are some examples attached: the clean one (square format with full black and white picture) worked but the others (which are pictures) do not work even if i put contrasts to maximum to get full black and full white colors.

edit: my error seems to be in ReedSolomonDecoder.php:82 when it calls findErrorLocations() function... Can't go much further than seeing i'm entering in the exception line 166 "Error locator degree does not match number of roots"

qr-code test5d2605cb9f0e4-carre test5d2605cb9f0e4-rond

lenny64 avatar Aug 06 '19 10:08 lenny64

Maybe for someone will be usefull this code snipet

// temp file name
$detectName = tempnam("/tmp", "detect");
// open image
$detect = imagecreatefromjpeg($imageFile);

if( ! $detect) {
  throw new Zend_Exception("Can't open file!");
}

// resizing image (we have a large images, decide yourself keep this part or not)
$w = imagesx($detect);
$h = imagesy($detect);

$p  = 800 * 100 / $w;
$nh = (int) ($h * $p / 100);
$nw = 800;

$resized = imagecreatetruecolor($nw, $nh);
imagecopyresampled($resized, $detect, 0, 0, 0, 0, $nw, $nh, $w, $h);

// original resource not need more
imagedestroy($detect);

// result of decoding
$data = null;

// save image to the file
imagejpeg($resized, $detectName);

// start detecting
for($t = 0; $t < 3; $t++) {
  // try detect
  $qrcode = new \Zxing\QrReader($detectName);
  $data   = $qrcode->text();

  // success detect
  if($data) {
    break;
  }

  // bluring ...
  for ($x = 1; $x <= 10; $x++) {
    imagefilter($resized, IMG_FILTER_GAUSSIAN_BLUR, 999);
  } 

  // more filters
  imagefilter($resized, IMG_FILTER_SMOOTH,     99);
  imagefilter($resized, IMG_FILTER_BRIGHTNESS, 10);

  // save image to the file
  imagejpeg($resized, $detectName);
}

imagedestroy($resized);

if( ! $data) {
  throw new Zend_Exception("QR код не найден на изображении!");
}

This helped me with good image quality and scanner artifacts.

jackkum avatar Oct 10 '19 02:10 jackkum

Well done @jackkum !

Since PHP 7.1 tempnam throws a notice and it could stop your process. To avoid that one can add the error control operator like this : $detectName = @tempnam("/tmp", "detect");

DjeeBay avatar Jun 08 '20 08:06 DjeeBay