php-qrcode-detector-decoder
php-qrcode-detector-decoder copied to clipboard
QRcode not decoding getting blank response
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
me too
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.
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"
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.
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");