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

Feature: print QR options #371

Merged
merged 4 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 62 additions & 14 deletions api/print.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
require_once '../lib/applyText.php';
require_once '../lib/log.php';

function applyQR($sourceResource, $qrPath, $x, $y) {
$qr = imagecreatefrompng($qrPath);
imagecopy($sourceResource, $qr, $x, $y, 0, 0, imagesx($qr), imagesy($qr));
return $sourceResource;
}

if (empty($_GET['filename'])) {
$errormsg = basename($_SERVER['PHP_SELF']) . ': No file provided!';
logErrorAndDie($errormsg);
Expand Down Expand Up @@ -54,11 +60,13 @@
$image = imagecreatefromjpeg($filename_source);
imagejpeg($image, $filename_print, $quality);
imagedestroy($image); // Destroy the created collage in memory
$rotateQr = false;
} else {
$image = imagecreatefromjpeg($filename_source);
$resultRotated = imagerotate($image, 90, 0); // Rotate image
imagejpeg($resultRotated, $filename_print, $quality);
imagedestroy($image); // Destroy the created collage in memory
$rotateQr = true;
// re-define width & height after rotation
list($width, $height) = getimagesize($filename_print);
}
Expand All @@ -74,27 +82,67 @@
$url = $config['qr']['url'];
}
include '../vendor/phpqrcode/lib/full/qrlib.php';
QRcode::png($url, $filename_codes, QR_ECLEVEL_H, 10);
switch ($config['qr']['ecLevel']) {
case 'QR_ECLEVEL_L':
$ecLevel = QR_ECLEVEL_L;
break;
case 'QR_ECLEVEL_M':
$ecLevel = QR_ECLEVEL_M;
break;
case 'QR_ECLEVEL_Q':
$ecLevel = QR_ECLEVEL_Q;
break;
case 'QR_ECLEVEL_H':
$ecLevel = QR_ECLEVEL_H;
break;
default:
$ecLevel = QR_ECLEVEL_M;
break;
}
QRcode::png($url, $filename_codes, $ecLevel, $config['print']['qrSize']);
if ($rotateQr) {
$image = imagecreatefrompng($filename_codes);
$resultRotated = imagerotate($image, 90, 0);
imagepng($resultRotated, $filename_codes, 0);
imagedestroy($image);
}
}

// merge source and code
$newwidth = $width + $height / 2;
$newheight = $height;

if ($config['print']['print_frame'] && testFile($config['print']['frame'])) {
$source = applyFrame($source, $print_frame);
}

$code = imagecreatefrompng($filename_codes);
$print = imagecreatetruecolor($newwidth, $newheight);
list($qrWidth, $qrHeight) = getimagesize($filename_codes);

if (is_numeric($config['print']['qrOffset'])) {
$offset = $config['print']['qrOffset'];
} else {
$offset = 10;
}

imagefill($print, 0, 0, imagecolorallocate($print, 255, 255, 255));
imagecopy($print, $source, 0, 0, 0, 0, $width, $height);
imagecopyresized($print, $code, $width, 0, 0, 0, $height / 2, $height / 2, imagesx($code), imagesy($code));
imagejpeg($print, $filename_print, $quality);
imagedestroy($code);
imagedestroy($print);
$source = imagecreatefromjpeg($filename_print);
switch ($config['print']['qrPosition']) {
case 'topLeft':
$x = $offset;
$y = $offset;
break;
case 'topRight':
$x = $width - ($qrWidth + $offset);
$y = $offset;
break;
case 'bottomRight':
$x = $width - ($qrWidth + $offset);
$y = $height - ($qrHeight + $offset);
break;
case 'bottomLeft':
$x = $offset;
$y = $height - ($qrHeight + $offset);
break;
default:
$x = $width - ($qrWidth + $offset);
$y = $height - ($qrHeight + $offset);
break;
}
$source = applyQR($source, $filename_codes, $x, $y);
} else {
if ($config['print']['print_frame'] && testFile($config['print']['frame'])) {
$source = applyFrame($source, $print_frame);
Expand Down
20 changes: 19 additions & 1 deletion api/qrcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,22 @@
}

include '../vendor/phpqrcode/lib/full/qrlib.php';
QRcode::png($url, false, QR_ECLEVEL_H, 10);
switch ($config['qr']['ecLevel']) {
case 'QR_ECLEVEL_L':
$ecLevel = QR_ECLEVEL_L;
break;
case 'QR_ECLEVEL_M':
$ecLevel = QR_ECLEVEL_M;
break;
case 'QR_ECLEVEL_Q':
$ecLevel = QR_ECLEVEL_Q;
break;
case 'QR_ECLEVEL_H':
$ecLevel = QR_ECLEVEL_H;
break;
default:
$ecLevel = QR_ECLEVEL_M;
break;
}

QRcode::png($url, false, $ecLevel, 8);
4 changes: 4 additions & 0 deletions config/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@
$config['print']['time'] = '5000';
$config['print']['key'] = null;
$config['print']['qrcode'] = false;
$config['print']['qrSize'] = '4';
$config['print']['qrPosition'] = 'bottomRight';
$config['print']['qrOffset'] = 10;
$config['print']['print_frame'] = false;
$config['print']['frame'] = 'resources/img/frames/frame.png';
$config['print']['crop'] = false;
Expand All @@ -208,6 +211,7 @@

// Q R - C O D E
$config['qr']['enabled'] = true;
$config['qr']['ecLevel'] = 'QR_ECLEVEL_M';
$config['qr']['url'] = NULL;
$config['qr']['append_filename'] = true;
$config['qr']['custom_text'] = false;
Expand Down
43 changes: 43 additions & 0 deletions lib/configsetup.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,37 @@
'name' => 'print[qrcode]',
'value' => $config['print']['qrcode'],
],
'print_qrSize' => [
'view' => 'advanced',
'type' => 'range',
'placeholder' => $defaultConfig['print']['qrSize'],
'name' => 'print[qrSize]',
'value' => $config['print']['qrSize'],
'range_min' => 4,
'range_max' => 10,
'range_step' => 2,
'unit' => 'empty',
],
'print_qrPosition' => [
'view' => 'advanced',
'type' => 'select',
'name' => 'print[qrPosition]',
'placeholder' => $defaultConfig['print']['qrPosition'],
'options' => [
'topLeft' => 'top left',
'topRight' => 'top right',
'bottomLeft' => 'bottom left',
'bottomRight' => 'bottom right',
],
'value' => $config['print']['qrPosition'],
],
'print_qrOffset' => [
'view' => 'expert',
'type' => 'input',
'placeholder' => $defaultConfig['print']['qrOffset'],
'name' => 'print[qrOffset]',
'value' => $config['print']['qrOffset'],
],
'print_print_frame' => [
'view' => 'expert',
'type' => 'checkbox',
Expand Down Expand Up @@ -1278,6 +1309,18 @@
'name' => 'qr[enabled]',
'value' => $config['qr']['enabled'],
],
'qr_ecLevel' => [
'type' => 'select',
'name' => 'qr[ecLevel]',
'placeholder' => $defaultConfig['qr']['ecLevel'],
'options' => [
'QR_ECLEVEL_L' => 'L - smallest',
'QR_ECLEVEL_M' => 'M',
'QR_ECLEVEL_Q' => 'Q',
'QR_ECLEVEL_H' => 'H - best',
],
'value' => $config['qr']['ecLevel'],
],
'qr_url' => [
'view' => 'expert',
'type' => 'input',
Expand Down
16 changes: 12 additions & 4 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"folders:folders_images": "Image Folder",
"folders:folders_keying": "Keying Folder",
"folders:folders_print": "Print Folder",
"folders:folders_qrcodes": "QR-Code Folder",
"folders:folders_qrcodes": "QR Code Folder",
"folders:folders_thumbs": "Thumbnail Folder",
"folders:folders_tmp": "tmp Folder",
"foldersize": "Foldersize:",
Expand Down Expand Up @@ -398,7 +398,10 @@
"manual:print:print_from_result": "If enabled, a print button is visible on result screen.",
"manual:print:print_key": "Specify the key id to use that key to print a picture (e.g. 13 is the enter key). For example use <a href=\"https://keycode.info\" target=\"_blank\">https://keycode.info</a> to find out the key id.",
"manual:print:print_print_frame": "If enabled, a frame is applied on your picture at print.",
"manual:print:print_qrcode": "If enabled, a QR-Code is printed onto the right side of the picture while printing.",
"manual:print:print_qrOffset": "Define an offset value the QR Code is placed away from the edges of the picture.",
"manual:print:print_qrPosition": "QR Code position",
"manual:print:print_qrSize": "Define the size of the QR Code. 4 = small, 10 = extra large.",
"manual:print:print_qrcode": "If enabled, a QR Code is printed onto the right side of the picture while printing.",
"manual:print:print_time": "Enter in milliseconds, how long \"Started printing! Please wait....\" is displayed after a print job has started.",
"manual:print:textonprint_enabled": "If enabled, you can print some text onto your pictures.",
"manual:print:textonprint_font": "Enter the path to the font used to print text onto your image.",
Expand All @@ -413,7 +416,8 @@
"manual:print:textonprint_rotation": "Enter a value which is used as degrees the text gets rotated at print.",
"manual:qr:qr_append_filename": "If enabled, the image name will be added to the QR URL.",
"manual:qr:qr_custom_text": "If enabled, own defined help text will be visible below the QR Code.",
"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>",
"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>",
"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>",
"manual:qr:qr_text": "Define own help text which will be visible below the QR Code.",
"manual:qr:qr_url": "Define a URL to point at via QR Code.",
"manual:remotebuzzer:remotebuzzer_collagebutton": "For COLLAGE connect the hardware button to GPIO20. Pull GPIO to ground for to trigger. If enabled, long-press on PICTURE button will not trigger collage.",
Expand Down Expand Up @@ -524,7 +528,10 @@
"print:print_from_result": "Allow printing from result page",
"print:print_key": "Key code which triggers printing",
"print:print_print_frame": "Print frame on picture",
"print:print_qrcode": "QR-Code on the picture while printing",
"print:print_qrOffset": "QR Code offset",
"print:print_qrPosition": "QR Code position",
"print:print_qrSize": "QR Code size (4 = small, 10 = extra large)",
"print:print_qrcode": "QR Code on the picture while printing",
"print:print_time": "Printing time",
"print:textonprint_enabled": "Print text on image",
"print:textonprint_font": "Font",
Expand All @@ -542,6 +549,7 @@
"qr": "QR Code",
"qr:qr_append_filename": "Append filename to URL",
"qr:qr_custom_text": "Use own help text on QR",
"qr:qr_ecLevel": "QR Code error correction",
"qr:qr_enabled": "Use QR Codes",
"qr:qr_text": "Own help text",
"qr:qr_url": "URL for QR Code",
Expand Down