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

Commit 91bd068

Browse files
committed
feature: add option to add all images from collage to gallery
- Todo: Also delete single images (optional?) if collage is deleted from result screen. Change-Id: Ia21593f8948ce44a1964afdaacc2f347e9dde2de
1 parent bdb3f0e commit 91bd068

File tree

5 files changed

+185
-156
lines changed

5 files changed

+185
-156
lines changed

api/applyEffects.php

Lines changed: 116 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@
2222

2323
$file = $_POST['file'];
2424

25-
$filename_photo = $config['foldersAbs']['images'] . DIRECTORY_SEPARATOR . $file;
26-
$filename_keying = $config['foldersAbs']['keying'] . DIRECTORY_SEPARATOR . $file;
27-
$filename_tmp = $config['foldersAbs']['tmp'] . DIRECTORY_SEPARATOR . $file;
28-
$filename_thumb = $config['foldersAbs']['thumbs'] . DIRECTORY_SEPARATOR . $file;
29-
$picture_frame = realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $config['picture']['frame']);
3025
$picture_permissions = $config['picture']['permissions'];
3126
$thumb_size = substr($config['picture']['thumb_size'], 0, -2);
3227
$chroma_size = substr($config['keying']['size'], 0, -2);
@@ -88,11 +83,6 @@
8883
}
8984
} else {
9085
// Check picture configuration
91-
if (!file_exists($filename_tmp)) {
92-
$errormsg = 'File ' . $filename_tmp . ' does not exist';
93-
logErrorAndDie($errormsg);
94-
}
95-
9686
if ($config['picture']['take_frame']) {
9787
if (is_dir($picture_frame)) {
9888
$errormsg = 'Frame not set! ' . $picture_frame . ' is a path but needs to be a png!';
@@ -118,136 +108,160 @@
118108
}
119109
}
120110

111+
$srcImages = [];
112+
$srcImages[] = $file;
113+
114+
$filename_tmp = $config['foldersAbs']['tmp'] . DIRECTORY_SEPARATOR . $file;
115+
121116
// Process Collage
122117
if ($_POST['style'] === 'collage') {
123118
$collageBasename = substr($filename_tmp, 0, -4);
119+
$singleImageBase = substr($file, 0, -4);
120+
124121
$collageSrcImagePaths = [];
125122

126123
for ($i = 0; $i < $config['collage']['limit']; $i++) {
127124
$collageSrcImagePaths[] = $collageBasename . '-' . $i . '.jpg';
125+
if ($config['collage']['keep_single_images']) {
126+
$srcImages[] = $singleImageBase . '-' . $i . '.jpg';
127+
}
128128
}
129129

130130
if (!createCollage($collageSrcImagePaths, $filename_tmp, $image_filter)) {
131131
$errormsg = 'Could not create collage';
132132
logErrorAndDie($errormsg);
133133
}
134-
135-
if (!$config['picture']['keep_original']) {
136-
foreach ($collageSrcImagePaths as $tmp) {
137-
unlink($tmp);
138-
}
139-
}
140134
}
141135

142-
$imageResource = imagecreatefromjpeg($filename_tmp);
136+
foreach ($srcImages as $image) {
137+
$filename_photo = $config['foldersAbs']['images'] . DIRECTORY_SEPARATOR . $image;
138+
$filename_keying = $config['foldersAbs']['keying'] . DIRECTORY_SEPARATOR . $image;
139+
$filename_tmp = $config['foldersAbs']['tmp'] . DIRECTORY_SEPARATOR . $image;
140+
$filename_thumb = $config['foldersAbs']['thumbs'] . DIRECTORY_SEPARATOR . $image;
143141

144-
if ($_POST['style'] !== 'collage') {
145-
// Only jpg/jpeg are supported
146-
if (!$imageResource) {
147-
$errormsg = 'Could not read jpeg file. Are you taking raws?';
142+
if (!file_exists($filename_tmp)) {
143+
$errormsg = 'File ' . $filename_tmp . ' does not exist';
148144
logErrorAndDie($errormsg);
149145
}
150146

151-
if ($config['picture']['flip'] !== 'off') {
152-
if ($config['picture']['flip'] === 'horizontal') {
153-
imageflip($imageResource, IMG_FLIP_HORIZONTAL);
154-
} elseif ($config['picture']['flip'] === 'vertical') {
155-
imageflip($imageResource, IMG_FLIP_VERTICAL);
156-
} elseif ($config['picture']['flip'] === 'both') {
157-
imageflip($imageResource, IMG_FLIP_BOTH);
158-
}
159-
$imageModified = true;
147+
$imageResource = imagecreatefromjpeg($filename_tmp);
148+
149+
if ($_POST['style'] === 'collage' && $file != $image) {
150+
$editSingleCollage = true;
151+
$picture_frame = realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $config['collage']['frame']);
152+
} else {
153+
$editSingleCollage = false;
154+
$picture_frame = realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $config['picture']['frame']);
160155
}
161156

162-
// apply filter
163-
if ($image_filter) {
164-
applyFilter($image_filter, $imageResource);
165-
$imageModified = true;
157+
if ($_POST['style'] !== 'collage' || $editSingleCollage) {
158+
// Only jpg/jpeg are supported
159+
if (!$imageResource) {
160+
$errormsg = 'Could not read jpeg file. Are you taking raws?';
161+
logErrorAndDie($errormsg);
162+
}
163+
164+
if ($config['picture']['flip'] !== 'off') {
165+
if ($config['picture']['flip'] === 'horizontal') {
166+
imageflip($imageResource, IMG_FLIP_HORIZONTAL);
167+
} elseif ($config['picture']['flip'] === 'vertical') {
168+
imageflip($imageResource, IMG_FLIP_VERTICAL);
169+
} elseif ($config['picture']['flip'] === 'both') {
170+
imageflip($imageResource, IMG_FLIP_BOTH);
171+
}
172+
$imageModified = true;
173+
}
174+
175+
// apply filter
176+
if ($image_filter) {
177+
applyFilter($image_filter, $imageResource);
178+
$imageModified = true;
179+
}
180+
181+
if ($config['picture']['rotation'] !== '0') {
182+
$rotatedImg = imagerotate($imageResource, $config['picture']['rotation'], 0);
183+
$imageResource = $rotatedImg;
184+
$imageModified = true;
185+
}
186+
187+
if ($config['picture']['polaroid_effect'] && $_POST['style'] !== 'collage') {
188+
$polaroid_rotation = $config['picture']['polaroid_rotation'];
189+
$imageResource = effectPolaroid($imageResource, $polaroid_rotation, 200, 200, 200);
190+
$imageModified = true;
191+
}
192+
193+
if ($config['picture']['take_frame'] || ($editSingleCollage && $config['collage']['take_frame'] === 'always')) {
194+
$frame = imagecreatefrompng($picture_frame);
195+
$frame = resizePngImage($frame, imagesx($imageResource), imagesy($imageResource));
196+
$x = imagesx($imageResource) / 2 - imagesx($frame) / 2;
197+
$y = imagesy($imageResource) / 2 - imagesy($frame) / 2;
198+
imagecopy($imageResource, $frame, $x, $y, 0, 0, imagesx($frame), imagesy($frame));
199+
$imageModified = true;
200+
}
166201
}
167202

168-
if ($config['picture']['rotation'] !== '0') {
169-
$rotatedImg = imagerotate($imageResource, $config['picture']['rotation'], 0);
170-
$imageResource = $rotatedImg;
171-
$imageModified = true;
203+
if ($config['keying']['enabled'] || $_POST['style'] === 'chroma') {
204+
$chromaCopyResource = resizeImage($imageResource, $chroma_size, $chroma_size);
205+
imagejpeg($chromaCopyResource, $filename_keying, $config['jpeg_quality']['chroma']);
206+
imagedestroy($chromaCopyResource);
172207
}
173208

174-
if ($config['picture']['polaroid_effect'] && $_POST['style'] !== 'collage') {
175-
$polaroid_rotation = $config['picture']['polaroid_rotation'];
176-
$imageResource = effectPolaroid($imageResource, $polaroid_rotation, 200, 200, 200);
209+
if ($config['textonpicture']['enabled'] && $_POST['style'] !== 'collage') {
210+
imagejpeg($imageResource, $filename_photo, $config['jpeg_quality']['image']);
211+
imagedestroy($imageResource);
212+
ApplyText($filename_photo, $fontsize, $fontrot, $fontlocx, $fontlocy, $fontcolor, $fontpath, $line1text, $line2text, $line3text, $linespacing);
177213
$imageModified = true;
214+
$imageResource = imagecreatefromjpeg($filename_photo);
178215
}
179216

180-
if ($config['picture']['take_frame']) {
181-
$frame = imagecreatefrompng($picture_frame);
182-
$frame = resizePngImage($frame, imagesx($imageResource), imagesy($imageResource));
183-
$x = imagesx($imageResource) / 2 - imagesx($frame) / 2;
184-
$y = imagesy($imageResource) / 2 - imagesy($frame) / 2;
185-
imagecopy($imageResource, $frame, $x, $y, 0, 0, imagesx($frame), imagesy($frame));
186-
$imageModified = true;
217+
// image scale, create thumbnail
218+
$thumbResource = resizeImage($imageResource, $thumb_size, $thumb_size);
219+
220+
imagejpeg($thumbResource, $filename_thumb, $config['jpeg_quality']['thumb']);
221+
imagedestroy($thumbResource);
222+
223+
if ($imageModified || ($config['jpeg_quality']['image'] >= 0 && $config['jpeg_quality']['image'] < 100)) {
224+
imagejpeg($imageResource, $filename_photo, $config['jpeg_quality']['image']);
225+
// preserve jpeg meta data
226+
if ($config['picture']['preserve_exif_data'] && $config['exiftool']['cmd']) {
227+
$cmd = sprintf($config['exiftool']['cmd'], $filename_tmp, $filename_photo);
228+
$cmd .= ' 2>&1'; //Redirect stderr to stdout, otherwise error messages get lost.
229+
230+
exec($cmd, $output, $returnValue);
231+
232+
if ($returnValue) {
233+
$ErrorData = [
234+
'error' => 'exiftool returned with an error code',
235+
'cmd' => $cmd,
236+
'returnValue' => $returnValue,
237+
'output' => $output,
238+
];
239+
$ErrorString = json_encode($ErrorData);
240+
logError($ErrorData);
241+
die($ErrorString);
242+
}
243+
}
244+
} else {
245+
copy($filename_tmp, $filename_photo);
187246
}
188-
}
189247

190-
if ($config['keying']['enabled'] || $_POST['style'] === 'chroma') {
191-
$chromaCopyResource = resizeImage($imageResource, $chroma_size, $chroma_size);
192-
imagejpeg($chromaCopyResource, $filename_keying, $config['jpeg_quality']['chroma']);
193-
imagedestroy($chromaCopyResource);
194-
}
248+
if (!$config['picture']['keep_original']) {
249+
unlink($filename_tmp);
250+
}
195251

196-
if ($config['textonpicture']['enabled'] && $_POST['style'] !== 'collage') {
197-
imagejpeg($imageResource, $filename_photo, $config['jpeg_quality']['image']);
198252
imagedestroy($imageResource);
199-
ApplyText($filename_photo, $fontsize, $fontrot, $fontlocx, $fontlocy, $fontcolor, $fontpath, $line1text, $line2text, $line3text, $linespacing);
200-
$imageModified = true;
201-
$imageResource = imagecreatefromjpeg($filename_photo);
202-
}
203253

204-
// image scale, create thumbnail
205-
$thumbResource = resizeImage($imageResource, $thumb_size, $thumb_size);
206-
207-
imagejpeg($thumbResource, $filename_thumb, $config['jpeg_quality']['thumb']);
208-
imagedestroy($thumbResource);
209-
210-
if ($imageModified || ($config['jpeg_quality']['image'] >= 0 && $config['jpeg_quality']['image'] < 100)) {
211-
imagejpeg($imageResource, $filename_photo, $config['jpeg_quality']['image']);
212-
// preserve jpeg meta data
213-
if ($config['picture']['preserve_exif_data'] && $config['exiftool']['cmd']) {
214-
$cmd = sprintf($config['exiftool']['cmd'], $filename_tmp, $filename_photo);
215-
$cmd .= ' 2>&1'; //Redirect stderr to stdout, otherwise error messages get lost.
216-
217-
exec($cmd, $output, $returnValue);
218-
219-
if ($returnValue) {
220-
$ErrorData = [
221-
'error' => 'exiftool returned with an error code',
222-
'cmd' => $cmd,
223-
'returnValue' => $returnValue,
224-
'output' => $output,
225-
];
226-
$ErrorString = json_encode($ErrorData);
227-
logError($ErrorData);
228-
die($ErrorString);
254+
// insert into database
255+
if ($config['database']['enabled']) {
256+
if ($_POST['style'] !== 'chroma' || ($_POST['style'] === 'chroma' && $config['live_keying']['show_all'] === true)) {
257+
appendImageToDB($image);
229258
}
230259
}
231-
} else {
232-
copy($filename_tmp, $filename_photo);
233-
}
234-
235-
if (!$config['picture']['keep_original']) {
236-
unlink($filename_tmp);
237-
}
238260

239-
imagedestroy($imageResource);
240-
241-
// insert into database
242-
if ($config['database']['enabled']) {
243-
if ($_POST['style'] !== 'chroma' || ($_POST['style'] === 'chroma' && $config['live_keying']['show_all'] === true)) {
244-
appendImageToDB($file);
245-
}
261+
// Change permissions
262+
chmod($filename_photo, octdec($picture_permissions));
246263
}
247264

248-
// Change permissions
249-
chmod($filename_photo, octdec($picture_permissions));
250-
251265
if ($_POST['style'] === 'chroma' && $config['live_keying']['show_all'] === false) {
252266
unlink($filename_photo);
253267
unlink($filename_thumb);

config/config.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
$config['collage']['continuous_time'] = '5';
9696
// possible layout values: '2x2', '2x2-2', '2x4', '2x4-2', '1+3', '1+3-2', '3+1', '1+2'
9797
$config['collage']['layout'] = '2x2-2';
98+
$config['collage']['keep_single_images'] = false;
9899
// specify key id (e.g. 13 is the enter key) to use that key to take a collage (collage key)
99100
// use for example https://keycode.info to get the key code
100101
$config['collage']['key'] = null;

0 commit comments

Comments
 (0)