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

Commit 224ad98

Browse files
committed
collage: allow to define background color
Change-Id: Ifeb251ea6327c57e6c9aab4cfe249ef19f03550e
1 parent 2bd1c0c commit 224ad98

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

config/config.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
// specify key id (e.g. 13 is the enter key) to use that key to take a collage (collage key)
9898
// use for example https://keycode.info to get the key code
9999
$config['collage']['key'] = null;
100+
$config['collage']['background_color'] = '#ffffff';
100101
// possible take_frame values: 'off', 'always', 'once'
101102
$config['collage']['take_frame'] = 'off';
102103
$config['collage']['frame'] = 'resources/img/frames/frame.png';

lib/collage.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
require_once __DIR__ . '/polaroid.php';
99

1010
define('COLLAGE_LAYOUT', $config['collage']['layout']);
11+
define('COLLAGE_BACKGROUND_COLOR', $config['collage']['background_color']);
1112
define('COLLAGE_FRAME', realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $config['collage']['frame']));
1213
define('COLLAGE_TAKE_FRAME', $config['collage']['take_frame']);
1314
define('COLLAGE_LIMIT', $config['collage']['limit']);
@@ -37,9 +38,9 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
3738
$image_filter = $filter;
3839
}
3940

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

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

8485
if (PICTURE_ROTATION !== '0') {
85-
$rotatedImg = imagerotate($imageResource, PICTURE_ROTATION, $white);
86+
$rotatedImg = imagerotate($imageResource, PICTURE_ROTATION, $bg_color_hex);
8687
$imageResource = $rotatedImg;
8788
$imageModified = true;
8889
}
@@ -107,7 +108,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
107108
$landscape = false;
108109
for ($i = 0; $i < COLLAGE_LIMIT; $i++) {
109110
$tempImage = imagecreatefromjpeg($srcImagePaths[$i]);
110-
$tempSubRotated = imagerotate($tempImage, 90, $white);
111+
$tempSubRotated = imagerotate($tempImage, 90, $bg_color_hex);
111112
imagejpeg($tempSubRotated, $srcImagePaths[$i], $quality);
112113
imagedestroy($tempImage);
113114
}
@@ -117,7 +118,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
117118
switch (COLLAGE_LAYOUT) {
118119
case '2x2':
119120
$my_collage = imagecreatetruecolor($width, $height);
120-
$background = imagecolorallocate($my_collage, 0, 0, 0);
121+
$background = imagecolorallocate($my_collage, $bg_r, $bg_g, $bg_b);
121122
imagecolortransparent($my_collage, $background);
122123

123124
if ($landscape == false) {
@@ -145,7 +146,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
145146
$width = 1800;
146147
$height = 1200;
147148
$my_collage = imagecreatetruecolor($width, $height);
148-
$background = imagecolorallocate($my_collage, 255, 255, 255);
149+
$background = imagecolorallocate($my_collage, $bg_r, $bg_g, $bg_b);
149150
imagefill($my_collage, 0, 0, $background);
150151

151152
if ($landscape == false) {
@@ -180,15 +181,15 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
180181
}
181182

182183
$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]);
183-
$tempSubRotated = imagerotate($tempSubImage, $degrees, $white); // Rotate image
184+
$tempSubRotated = imagerotate($tempSubImage, $degrees, $bg_color_hex); // Rotate image
184185
imagecopy($my_collage, $tempSubRotated, $dX, $dY, 0, 0, $widthNew, $heightNew); // copy image to background
185186
imagedestroy($tempSubRotated); // Destroy temporary images
186187
imagedestroy($tempSubImage); // Destroy temporary images
187188
}
188189
break;
189190
case '2x4':
190191
$my_collage = imagecreatetruecolor($width, $height);
191-
$background = imagecolorallocate($my_collage, 255, 255, 255);
192+
$background = imagecolorallocate($my_collage, $bg_r, $bg_g, $bg_b);
192193
imagefill($my_collage, 0, 0, $background);
193194

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

209210
$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]);
210-
$tempSubRotated = imagerotate($tempSubImage, $degrees, $white);
211+
$tempSubRotated = imagerotate($tempSubImage, $degrees, $bg_color_hex);
211212
$images_rotated[] = resizeImage($tempSubRotated, $height / 3.3, $width / 3.5);
212213
}
213214

@@ -244,7 +245,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
244245
$width = 1800;
245246
$height = 1200;
246247
$my_collage = imagecreatetruecolor($width, $height);
247-
$background = imagecolorallocate($my_collage, 255, 255, 255);
248+
$background = imagecolorallocate($my_collage, $bg_r, $bg_g, $bg_b);
248249
imagefill($my_collage, 0, 0, $background);
249250

250251
if ($landscape) {
@@ -276,7 +277,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
276277
}
277278

278279
$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]);
279-
$tempSubRotated = imagerotate($tempSubImage, $degrees, $white); // Rotate image
280+
$tempSubRotated = imagerotate($tempSubImage, $degrees, $bg_color_hex); // Rotate image
280281
imagecopy($my_collage, $tempSubRotated, $dX, $dY, 0, 0, $widthNew, $heightNew); // copy image to background
281282
imagedestroy($tempSubRotated); // Destroy temporary images
282283
imagedestroy($tempSubImage); // Destroy temporary images
@@ -287,7 +288,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
287288
$width = 1800;
288289
$height = 1200;
289290
$my_collage = imagecreatetruecolor($width, $height);
290-
$background = imagecolorallocate($my_collage, 255, 255, 255);
291+
$background = imagecolorallocate($my_collage, $bg_r, $bg_g, $bg_b);
291292
imagefill($my_collage, 0, 0, $background);
292293

293294
if ($landscape == false) {
@@ -325,7 +326,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
325326
}
326327

327328
$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]);
328-
$tempSubRotated = imagerotate($tempSubImage, $degrees, $white); // Rotate image
329+
$tempSubRotated = imagerotate($tempSubImage, $degrees, $bg_color_hex); // Rotate image
329330
imagecopy($my_collage, $tempSubRotated, $dX, $dY, 0, 0, $widthNew, $heightNew); // copy image to background
330331
imagedestroy($tempSubRotated); // Destroy temporary images
331332
imagedestroy($tempSubImage); // Destroy temporary images
@@ -336,7 +337,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
336337
$width = 1800;
337338
$height = 1200;
338339
$my_collage = imagecreatetruecolor($width, $height);
339-
$background = imagecolorallocate($my_collage, 255, 255, 255);
340+
$background = imagecolorallocate($my_collage, $bg_r, $bg_g, $bg_b);
340341
imagefill($my_collage, 0, 0, $background);
341342

342343
if ($landscape == false) {
@@ -405,7 +406,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
405406
$width = 1800;
406407
$height = 1200;
407408
$my_collage = imagecreatetruecolor($width, $height);
408-
$background = imagecolorallocate($my_collage, 255, 255, 255);
409+
$background = imagecolorallocate($my_collage, $bg_r, $bg_g, $bg_b);
409410
imagefill($my_collage, 0, 0, $background);
410411

411412
if ($landscape == false) {
@@ -454,7 +455,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
454455
$degrees = 11;
455456
$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]);
456457
// Rotate image and add white background
457-
$tempRotate = imagerotate($tempSubImage, $degrees, $white);
458+
$tempRotate = imagerotate($tempSubImage, $degrees, $bg_color_hex);
458459
imagejpeg($tempRotate, $srcImagePaths[$i], $quality);
459460
// get new width and height after rotation
460461
list($widthNew, $heightNew) = getimagesize($srcImagePaths[$i]);
@@ -463,7 +464,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
463464
}
464465
$degrees = 0;
465466
$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]);
466-
$tempSubRotated = imagerotate($tempSubImage, $degrees, $white); // Rotate image
467+
$tempSubRotated = imagerotate($tempSubImage, $degrees, $bg_color_hex); // Rotate image
467468
imagecopy($my_collage, $tempSubRotated, $dX, $dY, 0, 0, $widthNew, $heightNew); // copy image to background
468469
imagedestroy($tempSubRotated); // Destroy temporary images
469470
imagedestroy($tempSubImage); // Destroy temporary images
@@ -501,7 +502,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') {
501502
// Rotate image if needed
502503
if ($rotate_after_creation) {
503504
$tempRotatedImage = imagecreatefromjpeg($destImagePath);
504-
$resultRotated = imagerotate($tempRotatedImage, -90, $white);
505+
$resultRotated = imagerotate($tempRotatedImage, -90, $bg_color_hex);
505506
imagejpeg($resultRotated, $destImagePath, $quality);
506507
imagedestroy($tempRotatedImage);
507508
}

lib/configsetup.inc.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,13 @@
631631
'placeholder' => '',
632632
'value' => $config['collage']['key'],
633633
],
634+
'collage_background_color' => [
635+
'view' => 'basic',
636+
'type' => 'color',
637+
'name' => 'collage[background_color]',
638+
'placeholder' => $defaultConfig['collage']['background_color'],
639+
'value' => $config['collage']['background_color'],
640+
],
634641
'collage_take_frame' => [
635642
'view' => 'advanced',
636643
'type' => 'select',

resources/lang/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"chromaInfoBefore": "Please choose a background to take a Picture",
3232
"close": "Close",
3333
"collage": "Collage",
34+
"collage:collage_background_color": "Collage background color",
3435
"collage:collage_cntdwn_time": "Collage-countdown timer:",
3536
"collage:collage_continuous": "Take collage without interruption",
3637
"collage:collage_continuous_time": "Show single images on continuous collage for:",

0 commit comments

Comments
 (0)