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

Commit

Permalink
feature (collage): choose between 2x2 & 2x4 pictures on collage
Browse files Browse the repository at this point in the history
Implementation by alzo425: alzo425/photobooth@90099f1

Adjustments:
- Only use collage related changes.
- Fixed spaces.
- Adjusted config.
- Fixed Windows compatibility.

Change-Id: Ie371872e774a9cccf4da2cf507d929f1e55db177
  • Loading branch information
andi34 committed Sep 14, 2020
1 parent a5a26a2 commit 5864375
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 27 deletions.
3 changes: 2 additions & 1 deletion api/applyEffects.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
$filename_thumb = $config['foldersAbs']['thumbs'] . DIRECTORY_SEPARATOR . $file;
$frame_path = __DIR__ . DIRECTORY_SEPARATOR .$config['take_frame_path'];
$collage_frame_path = __DIR__ . DIRECTORY_SEPARATOR .$config['take_collage_frame_path'];
$collage_background = __DIR__ . DIRECTORY_SEPARATOR .$config['collage_background'];
$picture_permissions = $config['picture_permissions'];

if (isset($_POST['isCollage']) && $_POST['isCollage'] === 'true') {
Expand All @@ -32,7 +33,7 @@
$collageSrcImagePaths[] = $collageBasename . '-' . $i . '.jpg';
}

if (!createCollage($collageSrcImagePaths, $filename_tmp, $config['take_collage_frame'], $collage_frame_path)) {
if (!createCollage($collageSrcImagePaths, $filename_tmp, $config['take_collage_frame'], $collage_frame_path, $config['collage_layout'], $collage_background)) {
die(json_encode([
'error' => 'Could not create collage'
]));
Expand Down
2 changes: 2 additions & 0 deletions config/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
$config['take_frame_path'] = '../resources/img/frames/frame.png';
$config['take_collage_frame'] = false;
$config['take_collage_frame_path'] = '../resources/img/frames/frame.png';
$config['collage_layout'] = '2x2'; // possible values are '2x2' or '2x4'
$config['collage_background'] = '../resources/img/frames/DefaultCollageBackground.png';
$config['chroma_keying'] = false;
$config['use_collage'] = true;
$config['continuous_collage'] = true;
Expand Down
84 changes: 58 additions & 26 deletions lib/collage.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,73 @@
<?php

function createCollage($srcImagePaths, $destImagePath, $takeFrame, $framePath) {
function createCollage($srcImagePaths, $destImagePath, $takeFrame, $framePath, $Layout, $background2x4) {

if (!is_array($srcImagePaths) || count($srcImagePaths) !== 4) {
return false;
}

list($width, $height) = getimagesize($srcImagePaths[0]);

$my_collage = imagecreatetruecolor($width, $height);
$background = imagecolorallocate($my_collage, 0, 0, 0);
imagecolortransparent($my_collage, $background);
switch($Layout) {
case '2x2':
list($width, $height) = getimagesize($srcImagePaths[0]);

$positions = [[0, 0], [$width / 2, 0], [0, $height / 2], [$width / 2, $height / 2]];
$my_collage = imagecreatetruecolor($width, $height);
$background = imagecolorallocate($my_collage, 0, 0, 0);
imagecolortransparent($my_collage, $background);

for ($i = 0; $i < 4; $i++) {
$position = $positions[$i];
$positions = [[0, 0], [$width / 2, 0], [0, $height / 2], [$width / 2, $height / 2]];

if (!file_exists($srcImagePaths[$i])) {
return false;
}
for ($i = 0; $i < 4; $i++) {
$position = $positions[$i];

$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]);
if (!file_exists($srcImagePaths[$i])) {
return false;
}

if ($takeFrame) {
$frame = imagecreatefrompng($framePath);
$frame = resizePngImage($frame, imagesx($tempSubImage), imagesy($tempSubImage));
$x = (imagesx($tempSubImage)/2) - (imagesx($frame)/2);
$y = (imagesy($tempSubImage)/2) - (imagesy($frame)/2);
imagecopy($tempSubImage, $frame, $x, $y, 0, 0, imagesx($frame), imagesy($frame));
}
$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]);

imagecopyresized($my_collage, $tempSubImage, $position[0], $position[1], 0, 0, $width / 2, $height / 2, $width, $height);
imagedestroy($tempSubImage);
}
imagecopyresized($my_collage, $tempSubImage, $position[0], $position[1], 0, 0, $width / 2, $height / 2, $width, $height);
imagedestroy($tempSubImage);
}
if ($takeFrame) {
$frame = imagecreatefrompng($framePath);
$frame = resizePngImage($frame, $width, $height);
imagecopy($my_collage, $frame, 0, 0, 0, 0, $width, $height);
}
imagejpeg($my_collage, $destImagePath);
imagedestroy($my_collage);
break;
case '2x4':
$widthNew=321;
$heightNew=482;
$PositionsX = [63, 423, 785, 1146]; //X offset in Pixel
$PositionsY =[57, 642]; //Y offset in Pixel
$my_collage= imagecreatefrompng($background2x4);

imagejpeg($my_collage, $destImagePath);
imagedestroy($my_collage);
for ($j = 0; $j < 2; $j++) { //delta Y
$dY =$PositionsY[$j];
for ($i = 0; $i < 4; $i++) { // delta X
$dX =$PositionsX[$i];
if (!file_exists($srcImagePaths[$i])) {
return false;
}
$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]);
$tempSubRotated = imagerotate($tempSubImage, 90, 0);// Rotate image
list($width, $height) = getimagesize($srcImagePaths[0]);
imagecopyresized($my_collage, $tempSubRotated, $dX, $dY, 0, 0, $widthNew, $heightNew, $height, $width); // copy image to background
imagedestroy($tempSubImage); // Destroy temporary images
imagedestroy($tempSubRotated); // Destroy temporary images
}
}
imagejpeg($my_collage, $destImagePath); // Transfer immage to destImagePath with returns the image to core
imagedestroy($my_collage); // Destroy the created collage in memory
break;
default:
list($width, $height) = getimagesize($srcImagePaths[0]);

$my_collage = imagecreatetruecolor($width, $height);
imagejpeg($my_collage, $destImagePath); // Transfer immage to destImagePath with returns the image to core
imagedestroy($my_collage); // Destroy the created collage in memory
break;
}
return true;
}
}
16 changes: 16 additions & 0 deletions lib/configsetup.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,22 @@
'name' => 'take_collage_frame_path',
'value' => htmlentities($config['take_collage_frame_path'])
],
'collage_layout' => [
'type' => 'select',
'name' => 'collage_layout',
'placeholder' => $defaultConfig['collage_layout'],
'options' => [
'2x2' => '2x2',
'2x4' => '2x4'
],
'value' => $config['collage_layout']
],
'collage_background' => [
'type' => 'input',
'name' => 'collage_background',
'placeholder' => $defaultConfig['collage_background'],
'value' => $config['collage_background']
],
'collage_cntdwn_time' => [
'type' => 'range',
'name' => 'collage_cntdwn_time',
Expand Down
Binary file added resources/img/frames/DefaultCollageBackground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@
"general_camera_mode": "Camera facing mode",
"general_cheese_time": "Cheeeeeeeese!-Timer:",
"general_cntdwn_time": "Countdown timer:",
"general_collage_background": "Path to the background for 2x4 collage",
"general_collage_cntdwn_time": "Collage-countdown timer:",
"general_collage_key": "Key code which triggers a collage",
"general_collage_layout": "Choose collage layout:",
"general_db_file": "Database file name",
"general_default_imagefilter": "Default image filter",
"general_disabled_filters": "Disabled image filters",
Expand Down Expand Up @@ -142,8 +144,10 @@
"manual_general_camera_mode": "Choose between front- or back facing camera mode of your device cam.",
"manual_general_cheese_time": "Set a time to display \"Cheeeeeeeese!\" after the countdown.",
"manual_general_cntdwn_time": "Set your countdown time.",
"manual_general_collage_background": "Enter the path of the background which is applied to your collage on 2x4 collage layout.",
"manual_general_collage_cntdwn_time": "Set your countdown time between pictures while taking a collage.",
"manual_general_collage_key": "Specify the key id to use that key to take a collage (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_general_collage_layout": "Choose between 2x2 and 2x4 pictures collage layout.",
"manual_general_db_file": "Name of the database file.",
"manual_general_default_imagefilter": "Choose an image filter which is applied by default after taking a picture.",
"manual_general_disabled_filters": "Choose filters which get removed from the available image filters.",
Expand Down

0 comments on commit 5864375

Please sign in to comment.