From e2934c10d52553151ffbfbad4f00a2afd4838e65 Mon Sep 17 00:00:00 2001 From: Andreas Blaesius Date: Mon, 24 Jan 2022 22:02:29 +0100 Subject: [PATCH] feature(qr): place QR code onto the picture at print New settings from print: - QR size adjustable - QR offset adjustable - QR position adjustable By default place the QR-Code on the bottom right corner, use an small QR-Code with an small offset of 10px to the edges. Change-Id: I28baec6a6d0903cb47e3bf4145a751510740d3c0 --- api/print.php | 59 ++++++++++++++++++++++++++++++----------- config/config.inc.php | 3 +++ lib/configsetup.inc.php | 31 ++++++++++++++++++++++ resources/lang/en.json | 6 +++++ 4 files changed, 84 insertions(+), 15 deletions(-) diff --git a/api/print.php b/api/print.php index e57f60271..d627a36f6 100644 --- a/api/print.php +++ b/api/print.php @@ -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); @@ -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); } @@ -74,27 +82,48 @@ $url = $config['qr']['url']; } include '../vendor/phpqrcode/lib/full/qrlib.php'; - QRcode::png($url, $filename_codes, QR_ECLEVEL_H, 10); + QRcode::png($url, $filename_codes, QR_ECLEVEL_H, $config['print']['qrSize']); + if ($rotateQr) { + $image = imagecreatefrompng($filename_codes); + $resultRotated = imagerotate($image, 90, 0); // Rotate image + imagepng($resultRotated, $filename_codes, 0); + imagedestroy($image); // Destroy the created collage in memory + } } - // 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); - - 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); + list($qrWidth, $qrHeight) = getimagesize($filename_codes); + + $offset = $config['print']['qrOffset']; + + 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); diff --git a/config/config.inc.php b/config/config.inc.php index d9d17228f..2b0c12bb1 100644 --- a/config/config.inc.php +++ b/config/config.inc.php @@ -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; diff --git a/lib/configsetup.inc.php b/lib/configsetup.inc.php index 7f838b2ec..75e32315d 100644 --- a/lib/configsetup.inc.php +++ b/lib/configsetup.inc.php @@ -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', diff --git a/resources/lang/en.json b/resources/lang/en.json index 02d84671d..933aac50e 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -398,6 +398,9 @@ "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 https://keycode.info 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_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.", @@ -524,6 +527,9 @@ "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_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",