From e032babfde767774321eb5fa8e46daa5f27c8b63 Mon Sep 17 00:00:00 2001 From: Andreas Blaesius Date: Thu, 2 Sep 2021 20:16:22 +0200 Subject: [PATCH] feature: add option to add all images from collage to gallery Change-Id: Ia21593f8948ce44a1964afdaacc2f347e9dde2de --- api/applyEffects.php | 218 +++++++++++++++++++++------------------- config/config.inc.php | 1 + lib/collage.php | 116 +++++++++++---------- lib/configsetup.inc.php | 6 ++ resources/lang/en.json | 2 + 5 files changed, 186 insertions(+), 157 deletions(-) diff --git a/api/applyEffects.php b/api/applyEffects.php index 8869d1916..912681754 100644 --- a/api/applyEffects.php +++ b/api/applyEffects.php @@ -22,11 +22,6 @@ $file = $_POST['file']; -$filename_photo = $config['foldersAbs']['images'] . DIRECTORY_SEPARATOR . $file; -$filename_keying = $config['foldersAbs']['keying'] . DIRECTORY_SEPARATOR . $file; -$filename_tmp = $config['foldersAbs']['tmp'] . DIRECTORY_SEPARATOR . $file; -$filename_thumb = $config['foldersAbs']['thumbs'] . DIRECTORY_SEPARATOR . $file; -$picture_frame = realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $config['picture']['frame']); $picture_permissions = $config['picture']['permissions']; $thumb_size = substr($config['picture']['thumb_size'], 0, -2); $chroma_size = substr($config['keying']['size'], 0, -2); @@ -88,11 +83,6 @@ } } else { // Check picture configuration - if (!file_exists($filename_tmp)) { - $errormsg = 'File ' . $filename_tmp . ' does not exist'; - logErrorAndDie($errormsg); - } - if ($config['picture']['take_frame']) { if (is_dir($picture_frame)) { $errormsg = 'Frame not set! ' . $picture_frame . ' is a path but needs to be a png!'; @@ -118,136 +108,160 @@ } } +$srcImages = []; +$srcImages[] = $file; + +$filename_tmp = $config['foldersAbs']['tmp'] . DIRECTORY_SEPARATOR . $file; + // Process Collage if ($_POST['style'] === 'collage') { $collageBasename = substr($filename_tmp, 0, -4); + $singleImageBase = substr($file, 0, -4); + $collageSrcImagePaths = []; for ($i = 0; $i < $config['collage']['limit']; $i++) { $collageSrcImagePaths[] = $collageBasename . '-' . $i . '.jpg'; + if ($config['collage']['keep_single_images']) { + $srcImages[] = $singleImageBase . '-' . $i . '.jpg'; + } } if (!createCollage($collageSrcImagePaths, $filename_tmp, $image_filter)) { $errormsg = 'Could not create collage'; logErrorAndDie($errormsg); } - - if (!$config['picture']['keep_original']) { - foreach ($collageSrcImagePaths as $tmp) { - unlink($tmp); - } - } } -$imageResource = imagecreatefromjpeg($filename_tmp); +foreach ($srcImages as $image) { + $filename_photo = $config['foldersAbs']['images'] . DIRECTORY_SEPARATOR . $image; + $filename_keying = $config['foldersAbs']['keying'] . DIRECTORY_SEPARATOR . $image; + $filename_tmp = $config['foldersAbs']['tmp'] . DIRECTORY_SEPARATOR . $image; + $filename_thumb = $config['foldersAbs']['thumbs'] . DIRECTORY_SEPARATOR . $image; -if ($_POST['style'] !== 'collage') { - // Only jpg/jpeg are supported - if (!$imageResource) { - $errormsg = 'Could not read jpeg file. Are you taking raws?'; + if (!file_exists($filename_tmp)) { + $errormsg = 'File ' . $filename_tmp . ' does not exist'; logErrorAndDie($errormsg); } - if ($config['picture']['flip'] !== 'off') { - if ($config['picture']['flip'] === 'horizontal') { - imageflip($imageResource, IMG_FLIP_HORIZONTAL); - } elseif ($config['picture']['flip'] === 'vertical') { - imageflip($imageResource, IMG_FLIP_VERTICAL); - } elseif ($config['picture']['flip'] === 'both') { - imageflip($imageResource, IMG_FLIP_BOTH); - } - $imageModified = true; + $imageResource = imagecreatefromjpeg($filename_tmp); + + if ($_POST['style'] === 'collage' && $file != $image) { + $editSingleCollage = true; + $picture_frame = realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $config['collage']['frame']); + } else { + $editSingleCollage = false; + $picture_frame = realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $config['picture']['frame']); } - // apply filter - if ($image_filter) { - applyFilter($image_filter, $imageResource); - $imageModified = true; + if ($_POST['style'] !== 'collage' || $editSingleCollage) { + // Only jpg/jpeg are supported + if (!$imageResource) { + $errormsg = 'Could not read jpeg file. Are you taking raws?'; + logErrorAndDie($errormsg); + } + + if ($config['picture']['flip'] !== 'off') { + if ($config['picture']['flip'] === 'horizontal') { + imageflip($imageResource, IMG_FLIP_HORIZONTAL); + } elseif ($config['picture']['flip'] === 'vertical') { + imageflip($imageResource, IMG_FLIP_VERTICAL); + } elseif ($config['picture']['flip'] === 'both') { + imageflip($imageResource, IMG_FLIP_BOTH); + } + $imageModified = true; + } + + // apply filter + if ($image_filter) { + applyFilter($image_filter, $imageResource); + $imageModified = true; + } + + if ($config['picture']['rotation'] !== '0') { + $rotatedImg = imagerotate($imageResource, $config['picture']['rotation'], 0); + $imageResource = $rotatedImg; + $imageModified = true; + } + + if ($config['picture']['polaroid_effect'] && $_POST['style'] !== 'collage') { + $polaroid_rotation = $config['picture']['polaroid_rotation']; + $imageResource = effectPolaroid($imageResource, $polaroid_rotation, 200, 200, 200); + $imageModified = true; + } + + if ($config['picture']['take_frame'] || ($editSingleCollage && $config['collage']['take_frame'] === 'always')) { + $frame = imagecreatefrompng($picture_frame); + $frame = resizePngImage($frame, imagesx($imageResource), imagesy($imageResource)); + $x = imagesx($imageResource) / 2 - imagesx($frame) / 2; + $y = imagesy($imageResource) / 2 - imagesy($frame) / 2; + imagecopy($imageResource, $frame, $x, $y, 0, 0, imagesx($frame), imagesy($frame)); + $imageModified = true; + } } - if ($config['picture']['rotation'] !== '0') { - $rotatedImg = imagerotate($imageResource, $config['picture']['rotation'], 0); - $imageResource = $rotatedImg; - $imageModified = true; + if ($config['keying']['enabled'] || $_POST['style'] === 'chroma') { + $chromaCopyResource = resizeImage($imageResource, $chroma_size, $chroma_size); + imagejpeg($chromaCopyResource, $filename_keying, $config['jpeg_quality']['chroma']); + imagedestroy($chromaCopyResource); } - if ($config['picture']['polaroid_effect'] && $_POST['style'] !== 'collage') { - $polaroid_rotation = $config['picture']['polaroid_rotation']; - $imageResource = effectPolaroid($imageResource, $polaroid_rotation, 200, 200, 200); + if ($config['textonpicture']['enabled'] && $_POST['style'] !== 'collage') { + imagejpeg($imageResource, $filename_photo, $config['jpeg_quality']['image']); + imagedestroy($imageResource); + ApplyText($filename_photo, $fontsize, $fontrot, $fontlocx, $fontlocy, $fontcolor, $fontpath, $line1text, $line2text, $line3text, $linespacing); $imageModified = true; + $imageResource = imagecreatefromjpeg($filename_photo); } - if ($config['picture']['take_frame']) { - $frame = imagecreatefrompng($picture_frame); - $frame = resizePngImage($frame, imagesx($imageResource), imagesy($imageResource)); - $x = imagesx($imageResource) / 2 - imagesx($frame) / 2; - $y = imagesy($imageResource) / 2 - imagesy($frame) / 2; - imagecopy($imageResource, $frame, $x, $y, 0, 0, imagesx($frame), imagesy($frame)); - $imageModified = true; + // image scale, create thumbnail + $thumbResource = resizeImage($imageResource, $thumb_size, $thumb_size); + + imagejpeg($thumbResource, $filename_thumb, $config['jpeg_quality']['thumb']); + imagedestroy($thumbResource); + + if ($imageModified || ($config['jpeg_quality']['image'] >= 0 && $config['jpeg_quality']['image'] < 100)) { + imagejpeg($imageResource, $filename_photo, $config['jpeg_quality']['image']); + // preserve jpeg meta data + if ($config['picture']['preserve_exif_data'] && $config['exiftool']['cmd']) { + $cmd = sprintf($config['exiftool']['cmd'], $filename_tmp, $filename_photo); + $cmd .= ' 2>&1'; //Redirect stderr to stdout, otherwise error messages get lost. + + exec($cmd, $output, $returnValue); + + if ($returnValue) { + $ErrorData = [ + 'error' => 'exiftool returned with an error code', + 'cmd' => $cmd, + 'returnValue' => $returnValue, + 'output' => $output, + ]; + $ErrorString = json_encode($ErrorData); + logError($ErrorData); + die($ErrorString); + } + } + } else { + copy($filename_tmp, $filename_photo); } -} -if ($config['keying']['enabled'] || $_POST['style'] === 'chroma') { - $chromaCopyResource = resizeImage($imageResource, $chroma_size, $chroma_size); - imagejpeg($chromaCopyResource, $filename_keying, $config['jpeg_quality']['chroma']); - imagedestroy($chromaCopyResource); -} + if (!$config['picture']['keep_original']) { + unlink($filename_tmp); + } -if ($config['textonpicture']['enabled'] && $_POST['style'] !== 'collage') { - imagejpeg($imageResource, $filename_photo, $config['jpeg_quality']['image']); imagedestroy($imageResource); - ApplyText($filename_photo, $fontsize, $fontrot, $fontlocx, $fontlocy, $fontcolor, $fontpath, $line1text, $line2text, $line3text, $linespacing); - $imageModified = true; - $imageResource = imagecreatefromjpeg($filename_photo); -} -// image scale, create thumbnail -$thumbResource = resizeImage($imageResource, $thumb_size, $thumb_size); - -imagejpeg($thumbResource, $filename_thumb, $config['jpeg_quality']['thumb']); -imagedestroy($thumbResource); - -if ($imageModified || ($config['jpeg_quality']['image'] >= 0 && $config['jpeg_quality']['image'] < 100)) { - imagejpeg($imageResource, $filename_photo, $config['jpeg_quality']['image']); - // preserve jpeg meta data - if ($config['picture']['preserve_exif_data'] && $config['exiftool']['cmd']) { - $cmd = sprintf($config['exiftool']['cmd'], $filename_tmp, $filename_photo); - $cmd .= ' 2>&1'; //Redirect stderr to stdout, otherwise error messages get lost. - - exec($cmd, $output, $returnValue); - - if ($returnValue) { - $ErrorData = [ - 'error' => 'exiftool returned with an error code', - 'cmd' => $cmd, - 'returnValue' => $returnValue, - 'output' => $output, - ]; - $ErrorString = json_encode($ErrorData); - logError($ErrorData); - die($ErrorString); + // insert into database + if ($config['database']['enabled']) { + if ($_POST['style'] !== 'chroma' || ($_POST['style'] === 'chroma' && $config['live_keying']['show_all'] === true)) { + appendImageToDB($image); } } -} else { - copy($filename_tmp, $filename_photo); -} - -if (!$config['picture']['keep_original']) { - unlink($filename_tmp); -} -imagedestroy($imageResource); - -// insert into database -if ($config['database']['enabled']) { - if ($_POST['style'] !== 'chroma' || ($_POST['style'] === 'chroma' && $config['live_keying']['show_all'] === true)) { - appendImageToDB($file); - } + // Change permissions + chmod($filename_photo, octdec($picture_permissions)); } -// Change permissions -chmod($filename_photo, octdec($picture_permissions)); - if ($_POST['style'] === 'chroma' && $config['live_keying']['show_all'] === false) { unlink($filename_photo); unlink($filename_thumb); diff --git a/config/config.inc.php b/config/config.inc.php index eefb30f13..8dd590c8c 100644 --- a/config/config.inc.php +++ b/config/config.inc.php @@ -94,6 +94,7 @@ $config['collage']['continuous_time'] = '5'; // possible layout values: '2x2', '2x2-2', '2x4', '2x4-2', '1+3', '1+3-2', '3+1', '1+2' $config['collage']['layout'] = '2x2-2'; +$config['collage']['keep_single_images'] = false; // 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; diff --git a/lib/collage.php b/lib/collage.php index 898b47794..4c492ba2d 100644 --- a/lib/collage.php +++ b/lib/collage.php @@ -12,7 +12,6 @@ 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']); -define('PICTURE_KEEP_ORIGINAL', $config['picture']['keep_original'] === true ? 'keep' : 'discard'); define('PICTURE_FLIP', $config['picture']['flip']); define('PICTURE_ROTATION', $config['picture']['rotation']); define('PICTURE_POLAROID_EFFECT', $config['picture']['polaroid_effect'] === true ? 'enabled' : 'disabled'); @@ -30,6 +29,7 @@ define('TEXTONCOLLAGE_LINESPACE', $config['textoncollage']['linespace']); function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') { + $editImages = []; $rotate_after_creation = false; $quality = 100; $image_filter = false; @@ -52,19 +52,20 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') { logErrorAndDie($errormsg); } - $imageResource = imagecreatefromjpeg($srcImagePaths[$i]); + $singleimage = substr($srcImagePaths[$i], 0, -4); + $editfilename = $singleimage . '-edit.jpg'; + copy($srcImagePaths[$i], $editfilename); + $editImages[] = $editfilename; + } + + for ($i = 0; $i < COLLAGE_LIMIT; $i++) { + $imageResource = imagecreatefromjpeg($editImages[$i]); // Only jpg/jpeg are supported if (!$imageResource) { $errormsg = 'Could not read jpeg file. Are you taking raws?'; logErrorAndDie($errormsg); } - if (PICTURE_KEEP_ORIGINAL === 'keep') { - $singleimage = substr($srcImagePaths[$i], 0, -4); - $origfilename = $singleimage . '-orig.jpg'; - copy($srcImagePaths[$i], $origfilename); - } - if (PICTURE_FLIP !== 'off') { if (PICTURE_FLIP === 'horizontal') { imageflip($imageResource, IMG_FLIP_HORIZONTAL); @@ -95,24 +96,24 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') { } if ($imageModified) { - imagejpeg($imageResource, $srcImagePaths[$i], $quality); + imagejpeg($imageResource, $editImages[$i], $quality); } imagedestroy($imageResource); } - list($width, $height) = getimagesize($srcImagePaths[0]); + list($width, $height) = getimagesize($editImages[0]); if ($width > $height) { $landscape = true; } else { $landscape = false; for ($i = 0; $i < COLLAGE_LIMIT; $i++) { - $tempImage = imagecreatefromjpeg($srcImagePaths[$i]); + $tempImage = imagecreatefromjpeg($editImages[$i]); $tempSubRotated = imagerotate($tempImage, 90, $bg_color_hex); - imagejpeg($tempSubRotated, $srcImagePaths[$i], $quality); + imagejpeg($tempSubRotated, $editImages[$i], $quality); imagedestroy($tempImage); } - list($width, $height) = getimagesize($srcImagePaths[0]); + list($width, $height) = getimagesize($editImages[0]); } switch (COLLAGE_LAYOUT) { @@ -129,15 +130,15 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') { for ($i = 0; $i < 4; $i++) { $position = $positions[$i]; - if (!file_exists($srcImagePaths[$i])) { + if (!file_exists($editImages[$i])) { return false; } if (COLLAGE_TAKE_FRAME === 'always') { - ApplyFrame($srcImagePaths[$i], $srcImagePaths[$i], COLLAGE_FRAME); + ApplyFrame($editImages[$i], $editImages[$i], COLLAGE_FRAME); } - $tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]); + $tempSubImage = imagecreatefromjpeg($editImages[$i]); imagecopyresized($my_collage, $tempSubImage, $position[0], $position[1], 0, 0, $width / 2, $height / 2, $width, $height); imagedestroy($tempSubImage); } @@ -161,26 +162,26 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') { for ($i = 0; $i < 4; $i++) { if ($i < 2) { - ResizeCropImage($widthp, $heightp, $srcImagePaths[$i], $srcImagePaths[$i]); + ResizeCropImage($widthp, $heightp, $editImages[$i], $editImages[$i]); $dX = $PositionsX[$i]; $dY = $PositionsYtop; - list($widthNew, $heightNew) = getimagesize($srcImagePaths[$i]); + list($widthNew, $heightNew) = getimagesize($editImages[$i]); } else { - ResizeCropImage($widthp, $heightp, $srcImagePaths[$i], $srcImagePaths[$i]); + ResizeCropImage($widthp, $heightp, $editImages[$i], $editImages[$i]); $dX = $PositionsX[$i]; $dY = $PositionsYbot; - list($widthNew, $heightNew) = getimagesize($srcImagePaths[$i]); + list($widthNew, $heightNew) = getimagesize($editImages[$i]); } - if (!file_exists($srcImagePaths[$i])) { + if (!file_exists($editImages[$i])) { return false; } if (COLLAGE_TAKE_FRAME === 'always') { - ApplyFrame($srcImagePaths[$i], $srcImagePaths[$i], COLLAGE_FRAME); + ApplyFrame($editImages[$i], $editImages[$i], COLLAGE_FRAME); } - $tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]); + $tempSubImage = imagecreatefromjpeg($editImages[$i]); $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 @@ -199,15 +200,15 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') { $images_rotated = []; for ($i = 0; $i < 4; $i++) { - if (!file_exists($srcImagePaths[$i])) { + if (!file_exists($editImages[$i])) { return false; } if (COLLAGE_TAKE_FRAME === 'always') { - ApplyFrame($srcImagePaths[$i], $srcImagePaths[$i], COLLAGE_FRAME); + ApplyFrame($editImages[$i], $editImages[$i], COLLAGE_FRAME); } - $tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]); + $tempSubImage = imagecreatefromjpeg($editImages[$i]); $tempSubRotated = imagerotate($tempSubImage, $degrees, $bg_color_hex); $images_rotated[] = resizeImage($tempSubRotated, $height / 3.3, $width / 3.5); } @@ -258,9 +259,9 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') { $PositionsY = [64, 652]; //Y offset in Pixel for ($i = 0; $i < 4; $i++) { - ResizeCropImage($heightNew, $widthNew, $srcImagePaths[$i], $srcImagePaths[$i]); + ResizeCropImage($heightNew, $widthNew, $editImages[$i], $editImages[$i]); } - list($width, $height) = getimagesize($srcImagePaths[0]); + list($width, $height) = getimagesize($editImages[0]); for ($j = 0; $j < 2; $j++) { //delta Y @@ -268,15 +269,15 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') { for ($i = 0; $i < 4; $i++) { // delta X $dX = $PositionsX[$i]; - if (!file_exists($srcImagePaths[$i])) { + if (!file_exists($editImages[$i])) { return false; } if (COLLAGE_TAKE_FRAME === 'always') { - ApplyFrame($srcImagePaths[$i], $srcImagePaths[$i], COLLAGE_FRAME); + ApplyFrame($editImages[$i], $editImages[$i], COLLAGE_FRAME); } - $tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]); + $tempSubImage = imagecreatefromjpeg($editImages[$i]); $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 @@ -306,26 +307,26 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') { for ($i = 0; $i < 4; $i++) { if ($i == 0) { - ResizeCropImage($widthbig, $heightbig, $srcImagePaths[$i], $srcImagePaths[$i]); + ResizeCropImage($widthbig, $heightbig, $editImages[$i], $editImages[$i]); // delta X $dX = $PositionsXB; $dY = $PositionsYB; - list($widthNew, $heightNew) = getimagesize($srcImagePaths[0]); + list($widthNew, $heightNew) = getimagesize($editImages[0]); } else { - ResizeCropImage($widthsmall, $heightsmall, $srcImagePaths[$i], $srcImagePaths[$i]); + ResizeCropImage($widthsmall, $heightsmall, $editImages[$i], $editImages[$i]); $dX = $PositionsX[$i]; $dY = $PositionsYS; - list($widthNew, $heightNew) = getimagesize($srcImagePaths[$i]); + list($widthNew, $heightNew) = getimagesize($editImages[$i]); } - if (!file_exists($srcImagePaths[$i])) { + if (!file_exists($editImages[$i])) { return false; } if (COLLAGE_TAKE_FRAME === 'always') { - ApplyFrame($srcImagePaths[$i], $srcImagePaths[$i], COLLAGE_FRAME); + ApplyFrame($editImages[$i], $editImages[$i], COLLAGE_FRAME); } - $tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]); + $tempSubImage = imagecreatefromjpeg($editImages[$i]); $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 @@ -354,11 +355,11 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') { for ($i = 0; $i < 4; $i++) { $position = $positions[$i]; - if (!file_exists($srcImagePaths[$i])) { + if (!file_exists($editImages[$i])) { return false; } - list($picWidth, $picHeight) = getimagesize($srcImagePaths[$i]); + list($picWidth, $picHeight) = getimagesize($editImages[$i]); if (COLLAGE_LAYOUT === '1+3-2') { switch ($i) { // Picture 1, // Picture 2, // Picture 3, @@ -391,13 +392,13 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') { break; } } - ResizeCropImage($widthNew, $heightNew, $srcImagePaths[$i], $srcImagePaths[$i]); + ResizeCropImage($widthNew, $heightNew, $editImages[$i], $editImages[$i]); if (COLLAGE_TAKE_FRAME === 'always') { - ApplyFrame($srcImagePaths[$i], $srcImagePaths[$i], COLLAGE_FRAME); + ApplyFrame($editImages[$i], $editImages[$i], COLLAGE_FRAME); } - $tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]); + $tempSubImage = imagecreatefromjpeg($editImages[$i]); imagecopy($my_collage, $tempSubImage, $position[0], $position[1], 0, 0, $widthNew, $heightNew); // copy image to background imagedestroy($tempSubImage); } @@ -425,45 +426,45 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') { for ($i = 0; $i < 3; $i++) { if ($i == 0) { - ResizeCropImage($widthbig, $heightbig, $srcImagePaths[$i], $srcImagePaths[$i]); + ResizeCropImage($widthbig, $heightbig, $editImages[$i], $editImages[$i]); // delta X $dX = $PositionsXB; $dY = $PositionsYB; } elseif ($i == 1) { - ResizeCropImage($widthsmall, $heightsmall, $srcImagePaths[$i], $srcImagePaths[$i]); + ResizeCropImage($widthsmall, $heightsmall, $editImages[$i], $editImages[$i]); // delta X $dX = $PositionsX; $dY = $PositionsYS; - list($widthNew, $heightNew) = getimagesize($srcImagePaths[$i]); + list($widthNew, $heightNew) = getimagesize($editImages[$i]); } elseif ($i == 2) { - ResizeCropImage($widthsmall, $heightsmall, $srcImagePaths[$i], $srcImagePaths[$i]); + ResizeCropImage($widthsmall, $heightsmall, $editImages[$i], $editImages[$i]); // delta X $dX = $PositionsX; $dY = $PositionsYSs; - list($widthNew, $heightNew) = getimagesize($srcImagePaths[$i]); + list($widthNew, $heightNew) = getimagesize($editImages[$i]); } - if (!file_exists($srcImagePaths[$i])) { + if (!file_exists($editImages[$i])) { return false; } if (COLLAGE_TAKE_FRAME === 'always') { - ApplyFrame($srcImagePaths[$i], $srcImagePaths[$i], COLLAGE_FRAME); + ApplyFrame($editImages[$i], $editImages[$i], COLLAGE_FRAME); } if ($i == 0) { $degrees = 11; - $tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]); - // Rotate image and add white background + $tempSubImage = imagecreatefromjpeg($editImages[$i]); + // Rotate image and add background $tempRotate = imagerotate($tempSubImage, $degrees, $bg_color_hex); - imagejpeg($tempRotate, $srcImagePaths[$i], $quality); + imagejpeg($tempRotate, $editImages[$i], $quality); // get new width and height after rotation - list($widthNew, $heightNew) = getimagesize($srcImagePaths[$i]); + list($widthNew, $heightNew) = getimagesize($editImages[$i]); imagedestroy($tempRotate); imagedestroy($tempSubImage); } $degrees = 0; - $tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]); + $tempSubImage = imagecreatefromjpeg($editImages[$i]); $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 @@ -506,5 +507,10 @@ function createCollage($srcImagePaths, $destImagePath, $filter = 'plain') { imagejpeg($resultRotated, $destImagePath, $quality); imagedestroy($tempRotatedImage); } + + foreach ($editImages as $tmp) { + unlink($tmp); + } + return true; } diff --git a/lib/configsetup.inc.php b/lib/configsetup.inc.php index 2e3b9ad10..913f53a55 100644 --- a/lib/configsetup.inc.php +++ b/lib/configsetup.inc.php @@ -624,6 +624,12 @@ ], 'value' => $config['collage']['layout'], ], + 'collage_keep_single_images' => [ + 'view' => 'advanced', + 'type' => 'checkbox', + 'name' => 'collage[keep_single_images]', + 'value' => $config['collage']['keep_single_images'], + ], 'collage_key' => [ 'view' => 'expert', 'type' => 'input', diff --git a/resources/lang/en.json b/resources/lang/en.json index acad2f66f..fcae6f209 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -37,6 +37,7 @@ "collage:collage_continuous_time": "Show single images on continuous collage for:", "collage:collage_enabled": "Allow photo collage", "collage:collage_frame": "Frame", + "collage:collage_keep_single_images": "Add single images from collage to gallery", "collage:collage_key": "Key code which triggers a collage", "collage:collage_layout": "Choose collage layout:", "collage:collage_only": "Only allow photo collage", @@ -212,6 +213,7 @@ "manual:collage:collage_continuous_time": "Controll the time a picture is visible on continuous collage before the next picture is taken.", "manual:collage:collage_enabled": "If enabled, user can take a collage. A collage consists of 4 pictures. Optional you can take a collage with or without interruption.", "manual:collage:collage_frame": "Enter the path of the frame which is applied to your collage after taking it.", + "manual:collage:collage_keep_single_images": "If enabled, single images from collage will be added to the gallery. Please note that single images are not visible if you access the gallery at the result screen!", "manual:collage:collage_key": "Specify the key id to use that key to take a collage (e.g. 13 is the enter key). For example use https://keycode.info to find out the key id.", "manual:collage:collage_layout": "Choose between different collage layouts.", "manual:collage:collage_only": "If enabled, only collage can be taken.",