From d2713ed0fee520057a416ace50451b17ccac63fc Mon Sep 17 00:00:00 2001 From: Andreas Blaesius Date: Mon, 27 Sep 2021 08:49:43 +0200 Subject: [PATCH] collage: allow to define background color Change-Id: Ifeb251ea6327c57e6c9aab4cfe249ef19f03550e --- config/config.inc.php | 1 + lib/collage.php | 39 ++++++++++++++++++++------------------- lib/configsetup.inc.php | 7 +++++++ resources/lang/en.json | 1 + 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/config/config.inc.php b/config/config.inc.php index 3a5f0d41f..eefb30f13 100644 --- a/config/config.inc.php +++ b/config/config.inc.php @@ -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'; diff --git a/lib/collage.php b/lib/collage.php index 29a16f265..898b47794 100644 --- a/lib/collage.php +++ b/lib/collage.php @@ -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']); @@ -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; @@ -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; } @@ -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); } @@ -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) { @@ -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) { @@ -180,7 +181,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 @@ -188,7 +189,7 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') { 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) { @@ -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); } @@ -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) { @@ -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 @@ -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) { @@ -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 @@ -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) { @@ -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) { @@ -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]); @@ -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 @@ -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); } diff --git a/lib/configsetup.inc.php b/lib/configsetup.inc.php index ceb1a3080..2e3b9ad10 100644 --- a/lib/configsetup.inc.php +++ b/lib/configsetup.inc.php @@ -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', diff --git a/resources/lang/en.json b/resources/lang/en.json index 3df75d592..acad2f66f 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -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:",