Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
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
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'], $config['take_collage_frame_always'], $collage_frame_path, $collage_background)) {
die(json_encode([
'error' => 'Could not create collage'
]));
Expand Down
3 changes: 3 additions & 0 deletions config/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
$config['take_frame'] = false;
$config['take_frame_path'] = '../resources/img/frames/frame.png';
$config['take_collage_frame'] = false;
$config['take_collage_frame_always'] = 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
176 changes: 151 additions & 25 deletions lib/collage.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,167 @@
<?php
require_once(__DIR__ . '/config.php');

define('LAYOUT', $config['collage_layout']);

function createCollage($srcImagePaths, $destImagePath, $takeFrame, $takeFrameAlways, $framePath, $background_image) {

function createCollage($srcImagePaths, $destImagePath, $takeFrame, $framePath) {
if (!is_array($srcImagePaths) || count($srcImagePaths) !== 4) {
return false;
}

list($width, $height) = getimagesize($srcImagePaths[0]);
switch(LAYOUT) {
case '2x2':
list($width, $height) = getimagesize($srcImagePaths[0]);

$my_collage = imagecreatetruecolor($width, $height);
$background = imagecolorallocate($my_collage, 0, 0, 0);
imagecolortransparent($my_collage, $background);
$my_collage = imagecreatetruecolor($width, $height);
$background = imagecolorallocate($my_collage, 0, 0, 0);
imagecolortransparent($my_collage, $background);

$positions = [[0, 0], [$width / 2, 0], [0, $height / 2], [$width / 2, $height / 2]];
$positions = [[0, 0], [$width / 2, 0], [0, $height / 2], [$width / 2, $height / 2]];

for ($i = 0; $i < 4; $i++) {
$position = $positions[$i];
for ($i = 0; $i < 4; $i++) {
$position = $positions[$i];

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

$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]);
$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]);

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));
}
if ($takeFrame && $takeFrameAlways) {
$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));
}

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 && !$takeFrameAlways) {
$frame = imagecreatefrompng($framePath);
$frame = resizePngImage($frame, $width, $height);
$x = (imagesx($my_collage)/2) - (imagesx($frame)/2);
$y = (imagesy($my_collage)/2) - (imagesy($frame)/2);
imagecopy($my_collage, $frame, $x, $y, 0, 0, $width, $height);
}
imagejpeg($my_collage, $destImagePath);
imagedestroy($my_collage);
break;
case '2x4':
$degrees = 90;

list($width_before, $height_before) = getimagesize($srcImagePaths[0]);

$my_collage_width = $width_before;
$my_collage_height = $height_before;

$my_collage = imagecreatetruecolor($my_collage_width, $my_collage_height);
$background = imagecolorallocate($my_collage, 240, 240, 240);
imagefill($my_collage, 0, 0, $background);

$images_rotated = array();

for ($i = 0; $i < 4; $i++) {
$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]);

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

if ($takeFrame && $takeFrameAlways) {
$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));
}

$tempSubRotated = imagerotate($tempSubImage, $degrees, 0);
$images_rotated[] = resizeImage($tempSubRotated, $height_before/3.3, $width_before/3.5);
}

imagejpeg($my_collage, $destImagePath);
imagedestroy($my_collage);
if ($takeFrame && !$takeFrameAlways) {
$frame = imagecreatefrompng($framePath);
$frame = resizePngImage($frame, $my_collage_width, $my_collage_height);
$x = (imagesx($my_collage)/2) - (imagesx($frame)/2);
$y = (imagesy($my_collage)/2) - (imagesy($frame)/2);
imagecopy($my_collage, $frame, $x, $y, 0, 0, $my_collage_width, $my_collage_height);
}

$new_width = imagesx($images_rotated[0]);
$new_height = imagesy($images_rotated[0]);

$height_offset = ((($my_collage_height/2)-$new_height)/2);
$width_offset = (($my_collage_width-($new_width*4))/5);

$positions_top = [[$width_offset, $height_offset], [($width_offset*2+$new_width), $height_offset], [($width_offset*3+2*$new_width), $height_offset], [($width_offset*4+3*$new_width), $height_offset]];
$positions_bottom = [[$width_offset, ($new_height+(3*$height_offset))], [($width_offset*2+$new_width), ($new_height+(3*$height_offset))], [($width_offset*3+2*$new_width), ($new_height+(3*$height_offset))], [($width_offset*4+3*$new_width), ($new_height+(3*$height_offset))]];

for ($i = 0; $i < 4; $i++) {
$position_top = $positions_top[$i];
$position_bottom = $positions_bottom[$i];

imagecopy( $my_collage, $images_rotated[$i],$position_top[0],$position_top[1],0,0,$new_width,$new_height);
imagecopy( $my_collage, $images_rotated[$i],$position_bottom[0],$position_bottom[1],0,0,$new_width,$new_height);
}

imagescale($my_collage, $width_before, $height_before);

imagejpeg($my_collage, $destImagePath);
imagedestroy($my_collage);
break;
case '2x4BI':
$degrees = 90;
$widthNew=321;
$heightNew=482;
$PositionsX = [63, 423, 785, 1146]; //X offset in Pixel
$PositionsY =[57, 642]; //Y offset in Pixel
$my_collage= imagecreatefrompng($background_image);
list($bg_width, $bg_height) = getimagesize($background_image);

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]);

if ($takeFrame && $takeFrameAlways) {
$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));
}

$tempSubRotated = imagerotate($tempSubImage, $degrees, 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($tempSubRotated); // Destroy temporary images
imagedestroy($tempSubImage); // Destroy temporary images
}
}
if ($takeFrame && !$takeFrameAlways) {
$frame = imagecreatefrompng($framePath);
$frame = resizePngImage($frame, $bg_width, $bg_height);
$x = (imagesx($my_collage)/2) - (imagesx($frame)/2);
$y = (imagesy($my_collage)/2) - (imagesy($frame)/2);
imagecopy($my_collage, $frame, $x, $y, 0, 0, $bg_width, $bg_height);
}
imagejpeg($my_collage, $destImagePath); // Transfer image 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 image to destImagePath with returns the image to core
imagedestroy($my_collage); // Destroy the created collage in memory
break;
}
return true;
}
}
22 changes: 22 additions & 0 deletions lib/configsetup.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,34 @@
'name' => 'take_collage_frame',
'value' => $config['take_collage_frame']
],
'take_collage_frame_always' => [
'type' => 'checkbox',
'name' => 'take_collage_frame_always',
'value' => $config['take_collage_frame_always']
],
'take_collage_frame_path' => [
'type' => 'input',
'placeholder' => $defaultConfig['take_collage_frame_path'],
'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',
'2x4BI' => '2x4 + background image'
],
'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.
6 changes: 6 additions & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,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 + background image\" 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 @@ -144,8 +146,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 + background image\" 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 Expand Up @@ -246,6 +250,7 @@
"manual_slideshow_pictureTime": "Add a value which is used as milliseconds an image is displayed at standalone slideshow.",
"manual_slideshow_refreshTime": "Refresh standalone slideshow after entered seconds.",
"manual_take_collage_frame": "If enabled, defined frame will be applied to your collage after taking it.",
"manual_take_collage_frame_always": "If enabled, defined collage frame will be applied to each picture of your collage instead once after taking it. \"Take collage with frame\" needs to be enabled.",
"manual_take_frame": "If enabled, defined frame will be applied to your picture after taking it.",
"manual_toggle_fs_button": "If enabled, a button to toggle fullscreenmode will be added to the start screen.",
"manual_use_collage": "If enabled, user can take a collage. A collage consists of 4 pictures. Optional you can take a collage with or without interruption.",
Expand Down Expand Up @@ -353,6 +358,7 @@
"takeCollage": "Take Collage!",
"takePhoto": "Take Pic!",
"take_collage_frame": "Take collage with frame",
"take_collage_frame_always": "Apply frame to each picture of the collage",
"take_frame": "Take picture with frame",
"test_update_available": "There is a test update available.",
"toggleFullscreen": "Toggle Fullscreen",
Expand Down