88require_once __DIR__ . '/polaroid.php ' ;
99
1010define ('COLLAGE_LAYOUT ' , $ config ['collage ' ]['layout ' ]);
11+ define ('COLLAGE_BACKGROUND_COLOR ' , $ config ['collage ' ]['background_color ' ]);
1112define ('COLLAGE_FRAME ' , realpath (__DIR__ . DIRECTORY_SEPARATOR . '.. ' . DIRECTORY_SEPARATOR . $ config ['collage ' ]['frame ' ]));
1213define ('COLLAGE_TAKE_FRAME ' , $ config ['collage ' ]['take_frame ' ]);
1314define ('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 }
0 commit comments