From 20a9b16623431942aed1610e843ae6f2e665366b Mon Sep 17 00:00:00 2001 From: Andreas Blaesius Date: Sun, 8 Sep 2019 10:30:51 +0200 Subject: [PATCH] Allow printing frame on the picture - "frame.png" needes to be added in root of photobooth - only works if $config['print_qrcode'] = false; https://github.com/andi34/photobooth/issues/22 https://github.com/andreknieriem/photobooth/issues/67 --- admin/index.php | 5 +++++ config.inc.php | 1 + lang/de.js | 3 ++- lang/en.js | 3 ++- lang/fr.js | 3 ++- print.php | 22 ++++++++++++++++++++++ 6 files changed, 34 insertions(+), 3 deletions(-) diff --git a/admin/index.php b/admin/index.php index ea9d5d36e..cf37fd96d 100644 --- a/admin/index.php +++ b/admin/index.php @@ -57,6 +57,11 @@ 'name' => 'print_qrcode', 'value' => $config['print_qrcode'] ], + 'print_frame' => [ + 'type' => 'checkbox', + 'name' => 'print_frame', + 'value' => $config['print_frame'] + ], 'use_mail' => [ 'type' => 'checkbox', 'name' => 'use_mail', diff --git a/config.inc.php b/config.inc.php index 106e2e912..9ba1919c7 100644 --- a/config.inc.php +++ b/config.inc.php @@ -11,6 +11,7 @@ $config['use_print'] = false; $config['use_qr'] = true; $config['print_qrcode'] = true; +$config['print_frame'] == false; // only works if $config['print_qrcode'] = false; $config['use_mail'] = false; // mail data needs to be configured $config['use_mobile_view'] = false; $config['use_gpio_button'] = false; // Use alt+p to take a new picture, can be triggered via GPIO24 diff --git a/lang/de.js b/lang/de.js index 72ef44944..b5b62c979 100644 --- a/lang/de.js +++ b/lang/de.js @@ -86,5 +86,6 @@ L10N = { "symbol": "Symbol auswählen", "selectFilter": "Bildfilter", "use_filter": "Bildfilter erlauben", - "use_collage": "Foto-Collage erlauben" + "use_collage": "Foto-Collage erlauben", + "print_frame": "Rahmen auf Bild drucken" } diff --git a/lang/en.js b/lang/en.js index 6fdc9e5f6..c38e48b22 100644 --- a/lang/en.js +++ b/lang/en.js @@ -86,5 +86,6 @@ L10N = { "symbol": "Choose a symbol", "selectFilter": "Image filter", "use_filter": "Allow image filter", - "use_collage": "Allow collage photo" + "use_collage": "Allow collage photo", + "print_frame": "Print frame on picture" } diff --git a/lang/fr.js b/lang/fr.js index 0136fbeee..de3c33b6d 100644 --- a/lang/fr.js +++ b/lang/fr.js @@ -86,5 +86,6 @@ L10N = { "symbol": "Sélectionnez le symbole", "selectFilter": "Filtre d'image", "use_filter": "Autoriser le filtre d'image", - "use_collage": "Autoriser la fonction du montage photo" + "use_collage": "Autoriser la fonction du montage photo", + "print_frame": "Imprimer le cadre sur la photo" } diff --git a/print.php b/print.php index fef37653d..7a0f898eb 100644 --- a/print.php +++ b/print.php @@ -54,6 +54,13 @@ imagedestroy($source); } else { $print = imagecreatefromjpeg($filename_source); + if($config['print_frame'] == true) { + $rahmen = @imagecreatefrompng('frame.png'); + $rahmen = ResizePngImage($rahmen, imagesx($print), imagesy($print)); + $x = (imagesx($print)/2) - (imagesx($rahmen)/2); + $y = (imagesy($print)/2) - (imagesy($rahmen)/2); + imagecopy($print, $rahmen, $x, $y, 0, 0, imagesx($rahmen), imagesy($rahmen)); + } imagejpeg($print, $filename_print); } imagedestroy($print); @@ -69,3 +76,18 @@ ); echo json_encode(array('status' => 'ok', 'msg' => $printimage || '')); } + +function ResizePngImage($image, $max_width, $max_height) +{ + $old_width = imagesx($image); + $old_height = imagesy($image); + $scale = min($max_width/$old_width, $max_height/$old_height); + $new_width = ceil($scale*$old_width); + $new_height = ceil($scale*$old_height); + $new = imagecreatetruecolor($new_width, $new_height); + imagealphablending( $new, false ); + imagesavealpha( $new, true ); + imagecopyresized($new, $image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height); + + return $new; +}