|
22 | 22 |
|
23 | 23 | $file = $_POST['file']; |
24 | 24 |
|
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']); |
30 | 25 | $picture_permissions = $config['picture']['permissions']; |
31 | 26 | $thumb_size = substr($config['picture']['thumb_size'], 0, -2); |
32 | 27 | $chroma_size = substr($config['keying']['size'], 0, -2); |
|
88 | 83 | } |
89 | 84 | } else { |
90 | 85 | // Check picture configuration |
91 | | - if (!file_exists($filename_tmp)) { |
92 | | - $errormsg = 'File ' . $filename_tmp . ' does not exist'; |
93 | | - logErrorAndDie($errormsg); |
94 | | - } |
95 | | - |
96 | 86 | if ($config['picture']['take_frame']) { |
97 | 87 | if (is_dir($picture_frame)) { |
98 | 88 | $errormsg = 'Frame not set! ' . $picture_frame . ' is a path but needs to be a png!'; |
|
118 | 108 | } |
119 | 109 | } |
120 | 110 |
|
| 111 | +$srcImages = []; |
| 112 | +$srcImages[] = $file; |
| 113 | + |
| 114 | +$filename_tmp = $config['foldersAbs']['tmp'] . DIRECTORY_SEPARATOR . $file; |
| 115 | + |
121 | 116 | // Process Collage |
122 | 117 | if ($_POST['style'] === 'collage') { |
123 | 118 | $collageBasename = substr($filename_tmp, 0, -4); |
| 119 | + $singleImageBase = substr($file, 0, -4); |
| 120 | + |
124 | 121 | $collageSrcImagePaths = []; |
125 | 122 |
|
126 | 123 | for ($i = 0; $i < $config['collage']['limit']; $i++) { |
127 | 124 | $collageSrcImagePaths[] = $collageBasename . '-' . $i . '.jpg'; |
| 125 | + if ($config['collage']['keep_single_images']) { |
| 126 | + $srcImages[] = $singleImageBase . '-' . $i . '.jpg'; |
| 127 | + } |
128 | 128 | } |
129 | 129 |
|
130 | 130 | if (!createCollage($collageSrcImagePaths, $filename_tmp, $image_filter)) { |
131 | 131 | $errormsg = 'Could not create collage'; |
132 | 132 | logErrorAndDie($errormsg); |
133 | 133 | } |
134 | | - |
135 | | - if (!$config['picture']['keep_original']) { |
136 | | - foreach ($collageSrcImagePaths as $tmp) { |
137 | | - unlink($tmp); |
138 | | - } |
139 | | - } |
140 | 134 | } |
141 | 135 |
|
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; |
143 | 141 |
|
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'; |
148 | 144 | logErrorAndDie($errormsg); |
149 | 145 | } |
150 | 146 |
|
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']); |
160 | 155 | } |
161 | 156 |
|
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 | + } |
166 | 201 | } |
167 | 202 |
|
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); |
172 | 207 | } |
173 | 208 |
|
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); |
177 | 213 | $imageModified = true; |
| 214 | + $imageResource = imagecreatefromjpeg($filename_photo); |
178 | 215 | } |
179 | 216 |
|
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); |
187 | 246 | } |
188 | | -} |
189 | 247 |
|
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 | + } |
195 | 251 |
|
196 | | -if ($config['textonpicture']['enabled'] && $_POST['style'] !== 'collage') { |
197 | | - imagejpeg($imageResource, $filename_photo, $config['jpeg_quality']['image']); |
198 | 252 | 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 | | -} |
203 | 253 |
|
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); |
229 | 258 | } |
230 | 259 | } |
231 | | -} else { |
232 | | - copy($filename_tmp, $filename_photo); |
233 | | -} |
234 | | - |
235 | | -if (!$config['picture']['keep_original']) { |
236 | | - unlink($filename_tmp); |
237 | | -} |
238 | 260 |
|
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)); |
246 | 263 | } |
247 | 264 |
|
248 | | -// Change permissions |
249 | | -chmod($filename_photo, octdec($picture_permissions)); |
250 | | - |
251 | 265 | if ($_POST['style'] === 'chroma' && $config['live_keying']['show_all'] === false) { |
252 | 266 | unlink($filename_photo); |
253 | 267 | unlink($filename_thumb); |
|
0 commit comments