Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.

Commit c56d4d2

Browse files
committed
api(qr): make QR-Code error correction level adjustable
Lower default used error correction level from H to M. Information: https: //www.qrcode.com/en/about/error_correction.html https: //blog.qrstuff.com/2011/12/14/qr-code-error-correction Change-Id: I4849a340caeb4dfbc5933a90de4585ed8d932961
1 parent 12970c3 commit c56d4d2

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

api/print.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,24 @@ function applyQR($sourceResource, $qrPath, $x, $y) {
8282
$url = $config['qr']['url'];
8383
}
8484
include '../vendor/phpqrcode/lib/full/qrlib.php';
85-
QRcode::png($url, $filename_codes, QR_ECLEVEL_H, $config['print']['qrSize']);
85+
switch ($config['qr']['ecLevel']) {
86+
case 'QR_ECLEVEL_L':
87+
$ecLevel = QR_ECLEVEL_L;
88+
break;
89+
case 'QR_ECLEVEL_M':
90+
$ecLevel = QR_ECLEVEL_M;
91+
break;
92+
case 'QR_ECLEVEL_Q':
93+
$ecLevel = QR_ECLEVEL_Q;
94+
break;
95+
case 'QR_ECLEVEL_H':
96+
$ecLevel = QR_ECLEVEL_H;
97+
break;
98+
default:
99+
$ecLevel = QR_ECLEVEL_M;
100+
break;
101+
}
102+
QRcode::png($url, $filename_codes, $ecLevel, $config['print']['qrSize']);
86103
if ($rotateQr) {
87104
$image = imagecreatefrompng($filename_codes);
88105
$resultRotated = imagerotate($image, 90, 0);

api/qrcode.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,22 @@
1111
}
1212

1313
include '../vendor/phpqrcode/lib/full/qrlib.php';
14-
QRcode::png($url, false, QR_ECLEVEL_H, 10);
14+
switch ($config['qr']['ecLevel']) {
15+
case 'QR_ECLEVEL_L':
16+
$ecLevel = QR_ECLEVEL_L;
17+
break;
18+
case 'QR_ECLEVEL_M':
19+
$ecLevel = QR_ECLEVEL_M;
20+
break;
21+
case 'QR_ECLEVEL_Q':
22+
$ecLevel = QR_ECLEVEL_Q;
23+
break;
24+
case 'QR_ECLEVEL_H':
25+
$ecLevel = QR_ECLEVEL_H;
26+
break;
27+
default:
28+
$ecLevel = QR_ECLEVEL_M;
29+
break;
30+
}
31+
32+
QRcode::png($url, false, $ecLevel, 8);

config/config.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@
211211

212212
// Q R - C O D E
213213
$config['qr']['enabled'] = true;
214+
$config['qr']['ecLevel'] = 'QR_ECLEVEL_M';
214215
$config['qr']['url'] = NULL;
215216
$config['qr']['append_filename'] = true;
216217
$config['qr']['custom_text'] = false;

lib/configsetup.inc.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,18 @@
13091309
'name' => 'qr[enabled]',
13101310
'value' => $config['qr']['enabled'],
13111311
],
1312+
'qr_ecLevel' => [
1313+
'type' => 'select',
1314+
'name' => 'qr[ecLevel]',
1315+
'placeholder' => $defaultConfig['qr']['ecLevel'],
1316+
'options' => [
1317+
'QR_ECLEVEL_L' => 'L - smallest',
1318+
'QR_ECLEVEL_M' => 'M',
1319+
'QR_ECLEVEL_Q' => 'Q',
1320+
'QR_ECLEVEL_H' => 'H - best',
1321+
],
1322+
'value' => $config['qr']['ecLevel'],
1323+
],
13121324
'qr_url' => [
13131325
'view' => 'expert',
13141326
'type' => 'input',

resources/lang/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@
416416
"manual:print:textonprint_rotation": "Enter a value which is used as degrees the text gets rotated at print.",
417417
"manual:qr:qr_append_filename": "If enabled, the image name will be added to the QR URL.",
418418
"manual:qr:qr_custom_text": "If enabled, own defined help text will be visible below the QR Code.",
419+
"manual:qr:qr_ecLevel": "QR Code error correction capability to restore data:</br> Level L – up to 7%</br> Level M – up to 15%</br> Level Q – up to 25%</br> Level H – up to 30%</br>",
419420
"manual:qr:qr_enabled": "If enabled, a QR-Button is visible on the result screen and inside gallery. User can download a picture while scanning the QR-Code. If you're accessing Photobooth via \"localhost\", \"127.0.0.1\" or if you have Photobooth installed inside a subfolder, please define IP address of the Photobooth web server to make the QR-Code working. <p>Example if Photobooth can be accessed directly: <code>192.168.0.50</code>.</p><p>Example if Photobooth is installed inside a subfolder: <code>192.168.0.50/photobooth</code>.</p>",
420421
"manual:qr:qr_text": "Define own help text which will be visible below the QR Code.",
421422
"manual:qr:qr_url": "Define a URL to point at via QR Code.",
@@ -548,6 +549,7 @@
548549
"qr": "QR Code",
549550
"qr:qr_append_filename": "Append filename to URL",
550551
"qr:qr_custom_text": "Use own help text on QR",
552+
"qr:qr_ecLevel": "QR-Code error correction",
551553
"qr:qr_enabled": "Use QR Codes",
552554
"qr:qr_text": "Own help text",
553555
"qr:qr_url": "URL for QR Code",

0 commit comments

Comments
 (0)