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

Feature: collage background color #324

Merged
merged 1 commit into from Sep 27, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions config/config.inc.php
Expand Up @@ -97,6 +97,7 @@
// specify key id (e.g. 13 is the enter key) to use that key to take a collage (collage key)
// use for example https://keycode.info to get the key code
$config['collage']['key'] = null;
$config['collage']['background_color'] = '#ffffff';
// possible take_frame values: 'off', 'always', 'once'
$config['collage']['take_frame'] = 'off';
$config['collage']['frame'] = 'resources/img/frames/frame.png';
Expand Down
39 changes: 20 additions & 19 deletions lib/collage.php
Expand Up @@ -8,6 +8,7 @@
require_once __DIR__ . '/polaroid.php';

define('COLLAGE_LAYOUT', $config['collage']['layout']);
define('COLLAGE_BACKGROUND_COLOR', $config['collage']['background_color']);
define('COLLAGE_FRAME', realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $config['collage']['frame']));
define('COLLAGE_TAKE_FRAME', $config['collage']['take_frame']);
define('COLLAGE_LIMIT', $config['collage']['limit']);
Expand Down Expand Up @@ -37,9 +38,9 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
$image_filter = $filter;
}

// colors for background while rotating jpeg images
$white = 16777215;
$black = 0;
// colors for background and while rotating jpeg images
list($bg_r, $bg_g, $bg_b) = sscanf(COLLAGE_BACKGROUND_COLOR, '#%02x%02x%02x');
$bg_color_hex = hexdec(substr(COLLAGE_BACKGROUND_COLOR, 1));

if (!is_array($srcImagePaths) || count($srcImagePaths) !== COLLAGE_LIMIT) {
return false;
Expand Down Expand Up @@ -82,7 +83,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
}

if (PICTURE_ROTATION !== '0') {
$rotatedImg = imagerotate($imageResource, PICTURE_ROTATION, $white);
$rotatedImg = imagerotate($imageResource, PICTURE_ROTATION, $bg_color_hex);
$imageResource = $rotatedImg;
$imageModified = true;
}
Expand All @@ -107,7 +108,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
$landscape = false;
for ($i = 0; $i < COLLAGE_LIMIT; $i++) {
$tempImage = imagecreatefromjpeg($srcImagePaths[$i]);
$tempSubRotated = imagerotate($tempImage, 90, $white);
$tempSubRotated = imagerotate($tempImage, 90, $bg_color_hex);
imagejpeg($tempSubRotated, $srcImagePaths[$i], $quality);
imagedestroy($tempImage);
}
Expand All @@ -117,7 +118,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
switch (COLLAGE_LAYOUT) {
case '2x2':
$my_collage = imagecreatetruecolor($width, $height);
$background = imagecolorallocate($my_collage, 0, 0, 0);
$background = imagecolorallocate($my_collage, $bg_r, $bg_g, $bg_b);
imagecolortransparent($my_collage, $background);

if ($landscape == false) {
Expand Down Expand Up @@ -145,7 +146,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
$width = 1800;
$height = 1200;
$my_collage = imagecreatetruecolor($width, $height);
$background = imagecolorallocate($my_collage, 255, 255, 255);
$background = imagecolorallocate($my_collage, $bg_r, $bg_g, $bg_b);
imagefill($my_collage, 0, 0, $background);

if ($landscape == false) {
Expand Down Expand Up @@ -180,15 +181,15 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
}

$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]);
$tempSubRotated = imagerotate($tempSubImage, $degrees, $white); // Rotate image
$tempSubRotated = imagerotate($tempSubImage, $degrees, $bg_color_hex); // Rotate image
imagecopy($my_collage, $tempSubRotated, $dX, $dY, 0, 0, $widthNew, $heightNew); // copy image to background
imagedestroy($tempSubRotated); // Destroy temporary images
imagedestroy($tempSubImage); // Destroy temporary images
}
break;
case '2x4':
$my_collage = imagecreatetruecolor($width, $height);
$background = imagecolorallocate($my_collage, 255, 255, 255);
$background = imagecolorallocate($my_collage, $bg_r, $bg_g, $bg_b);
imagefill($my_collage, 0, 0, $background);

if ($landscape) {
Expand All @@ -207,7 +208,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
}

$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]);
$tempSubRotated = imagerotate($tempSubImage, $degrees, $white);
$tempSubRotated = imagerotate($tempSubImage, $degrees, $bg_color_hex);
$images_rotated[] = resizeImage($tempSubRotated, $height / 3.3, $width / 3.5);
}

Expand Down Expand Up @@ -244,7 +245,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
$width = 1800;
$height = 1200;
$my_collage = imagecreatetruecolor($width, $height);
$background = imagecolorallocate($my_collage, 255, 255, 255);
$background = imagecolorallocate($my_collage, $bg_r, $bg_g, $bg_b);
imagefill($my_collage, 0, 0, $background);

if ($landscape) {
Expand Down Expand Up @@ -276,7 +277,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
}

$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]);
$tempSubRotated = imagerotate($tempSubImage, $degrees, $white); // Rotate image
$tempSubRotated = imagerotate($tempSubImage, $degrees, $bg_color_hex); // Rotate image
imagecopy($my_collage, $tempSubRotated, $dX, $dY, 0, 0, $widthNew, $heightNew); // copy image to background
imagedestroy($tempSubRotated); // Destroy temporary images
imagedestroy($tempSubImage); // Destroy temporary images
Expand All @@ -287,7 +288,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
$width = 1800;
$height = 1200;
$my_collage = imagecreatetruecolor($width, $height);
$background = imagecolorallocate($my_collage, 255, 255, 255);
$background = imagecolorallocate($my_collage, $bg_r, $bg_g, $bg_b);
imagefill($my_collage, 0, 0, $background);

if ($landscape == false) {
Expand Down Expand Up @@ -325,7 +326,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
}

$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]);
$tempSubRotated = imagerotate($tempSubImage, $degrees, $white); // Rotate image
$tempSubRotated = imagerotate($tempSubImage, $degrees, $bg_color_hex); // Rotate image
imagecopy($my_collage, $tempSubRotated, $dX, $dY, 0, 0, $widthNew, $heightNew); // copy image to background
imagedestroy($tempSubRotated); // Destroy temporary images
imagedestroy($tempSubImage); // Destroy temporary images
Expand All @@ -336,7 +337,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
$width = 1800;
$height = 1200;
$my_collage = imagecreatetruecolor($width, $height);
$background = imagecolorallocate($my_collage, 255, 255, 255);
$background = imagecolorallocate($my_collage, $bg_r, $bg_g, $bg_b);
imagefill($my_collage, 0, 0, $background);

if ($landscape == false) {
Expand Down Expand Up @@ -405,7 +406,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
$width = 1800;
$height = 1200;
$my_collage = imagecreatetruecolor($width, $height);
$background = imagecolorallocate($my_collage, 255, 255, 255);
$background = imagecolorallocate($my_collage, $bg_r, $bg_g, $bg_b);
imagefill($my_collage, 0, 0, $background);

if ($landscape == false) {
Expand Down Expand Up @@ -454,7 +455,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
$degrees = 11;
$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]);
// Rotate image and add white background
$tempRotate = imagerotate($tempSubImage, $degrees, $white);
$tempRotate = imagerotate($tempSubImage, $degrees, $bg_color_hex);
imagejpeg($tempRotate, $srcImagePaths[$i], $quality);
// get new width and height after rotation
list($widthNew, $heightNew) = getimagesize($srcImagePaths[$i]);
Expand All @@ -463,7 +464,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
}
$degrees = 0;
$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]);
$tempSubRotated = imagerotate($tempSubImage, $degrees, $white); // Rotate image
$tempSubRotated = imagerotate($tempSubImage, $degrees, $bg_color_hex); // Rotate image
imagecopy($my_collage, $tempSubRotated, $dX, $dY, 0, 0, $widthNew, $heightNew); // copy image to background
imagedestroy($tempSubRotated); // Destroy temporary images
imagedestroy($tempSubImage); // Destroy temporary images
Expand Down Expand Up @@ -501,7 +502,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
// Rotate image if needed
if ($rotate_after_creation) {
$tempRotatedImage = imagecreatefromjpeg($destImagePath);
$resultRotated = imagerotate($tempRotatedImage, -90, $white);
$resultRotated = imagerotate($tempRotatedImage, -90, $bg_color_hex);
imagejpeg($resultRotated, $destImagePath, $quality);
imagedestroy($tempRotatedImage);
}
Expand Down
7 changes: 7 additions & 0 deletions lib/configsetup.inc.php
Expand Up @@ -631,6 +631,13 @@
'placeholder' => '',
'value' => $config['collage']['key'],
],
'collage_background_color' => [
'view' => 'basic',
'type' => 'color',
'name' => 'collage[background_color]',
'placeholder' => $defaultConfig['collage']['background_color'],
'value' => $config['collage']['background_color'],
],
'collage_take_frame' => [
'view' => 'advanced',
'type' => 'select',
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en.json
Expand Up @@ -31,6 +31,7 @@
"chromaInfoBefore": "Please choose a background to take a Picture",
"close": "Close",
"collage": "Collage",
"collage:collage_background_color": "Collage background color",
"collage:collage_cntdwn_time": "Collage-countdown timer:",
"collage:collage_continuous": "Take collage without interruption",
"collage:collage_continuous_time": "Show single images on continuous collage for:",
Expand Down