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

Commit

Permalink
feature(qr): place QR code onto the picture at print
Browse files Browse the repository at this point in the history
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
  • Loading branch information
andi34 committed Jan 24, 2022
1 parent 5deac70 commit e2934c1
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 15 deletions.
59 changes: 44 additions & 15 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,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);
Expand Down
3 changes: 3 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 Down
31 changes: 31 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
6 changes: 6 additions & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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_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.",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit e2934c1

Please sign in to comment.