This repository has been archived by the owner on Aug 27, 2022. It is now read-only.
forked from andreknieriem/photobooth
-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature (collage): choose between 2x2 & 2x4 pictures on collage
Implementation by alzo425: alzo425/photobooth@90099f1 Adjustments: - Only use collage related changes. - Fixed spaces. - Adjusted config. - Fixed Windows compatibility. Change-Id: Ie371872e774a9cccf4da2cf507d929f1e55db177
- Loading branch information
Showing
6 changed files
with
82 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,73 @@ | ||
<?php | ||
|
||
function createCollage($srcImagePaths, $destImagePath, $takeFrame, $framePath) { | ||
function createCollage($srcImagePaths, $destImagePath, $takeFrame, $framePath, $Layout, $background2x4) { | ||
|
||
if (!is_array($srcImagePaths) || count($srcImagePaths) !== 4) { | ||
return false; | ||
} | ||
|
||
list($width, $height) = getimagesize($srcImagePaths[0]); | ||
|
||
$my_collage = imagecreatetruecolor($width, $height); | ||
$background = imagecolorallocate($my_collage, 0, 0, 0); | ||
imagecolortransparent($my_collage, $background); | ||
switch($Layout) { | ||
case '2x2': | ||
list($width, $height) = getimagesize($srcImagePaths[0]); | ||
|
||
$positions = [[0, 0], [$width / 2, 0], [0, $height / 2], [$width / 2, $height / 2]]; | ||
$my_collage = imagecreatetruecolor($width, $height); | ||
$background = imagecolorallocate($my_collage, 0, 0, 0); | ||
imagecolortransparent($my_collage, $background); | ||
|
||
for ($i = 0; $i < 4; $i++) { | ||
$position = $positions[$i]; | ||
$positions = [[0, 0], [$width / 2, 0], [0, $height / 2], [$width / 2, $height / 2]]; | ||
|
||
if (!file_exists($srcImagePaths[$i])) { | ||
return false; | ||
} | ||
for ($i = 0; $i < 4; $i++) { | ||
$position = $positions[$i]; | ||
|
||
$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]); | ||
if (!file_exists($srcImagePaths[$i])) { | ||
return false; | ||
} | ||
|
||
if ($takeFrame) { | ||
$frame = imagecreatefrompng($framePath); | ||
$frame = resizePngImage($frame, imagesx($tempSubImage), imagesy($tempSubImage)); | ||
$x = (imagesx($tempSubImage)/2) - (imagesx($frame)/2); | ||
$y = (imagesy($tempSubImage)/2) - (imagesy($frame)/2); | ||
imagecopy($tempSubImage, $frame, $x, $y, 0, 0, imagesx($frame), imagesy($frame)); | ||
} | ||
$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]); | ||
|
||
imagecopyresized($my_collage, $tempSubImage, $position[0], $position[1], 0, 0, $width / 2, $height / 2, $width, $height); | ||
imagedestroy($tempSubImage); | ||
} | ||
imagecopyresized($my_collage, $tempSubImage, $position[0], $position[1], 0, 0, $width / 2, $height / 2, $width, $height); | ||
imagedestroy($tempSubImage); | ||
} | ||
if ($takeFrame) { | ||
$frame = imagecreatefrompng($framePath); | ||
$frame = resizePngImage($frame, $width, $height); | ||
imagecopy($my_collage, $frame, 0, 0, 0, 0, $width, $height); | ||
} | ||
imagejpeg($my_collage, $destImagePath); | ||
imagedestroy($my_collage); | ||
break; | ||
case '2x4': | ||
$widthNew=321; | ||
$heightNew=482; | ||
$PositionsX = [63, 423, 785, 1146]; //X offset in Pixel | ||
$PositionsY =[57, 642]; //Y offset in Pixel | ||
$my_collage= imagecreatefrompng($background2x4); | ||
|
||
imagejpeg($my_collage, $destImagePath); | ||
imagedestroy($my_collage); | ||
for ($j = 0; $j < 2; $j++) { //delta Y | ||
$dY =$PositionsY[$j]; | ||
for ($i = 0; $i < 4; $i++) { // delta X | ||
$dX =$PositionsX[$i]; | ||
if (!file_exists($srcImagePaths[$i])) { | ||
return false; | ||
} | ||
$tempSubImage = imagecreatefromjpeg($srcImagePaths[$i]); | ||
$tempSubRotated = imagerotate($tempSubImage, 90, 0);// Rotate image | ||
list($width, $height) = getimagesize($srcImagePaths[0]); | ||
imagecopyresized($my_collage, $tempSubRotated, $dX, $dY, 0, 0, $widthNew, $heightNew, $height, $width); // copy image to background | ||
imagedestroy($tempSubImage); // Destroy temporary images | ||
imagedestroy($tempSubRotated); // Destroy temporary images | ||
} | ||
} | ||
imagejpeg($my_collage, $destImagePath); // Transfer immage to destImagePath with returns the image to core | ||
imagedestroy($my_collage); // Destroy the created collage in memory | ||
break; | ||
default: | ||
list($width, $height) = getimagesize($srcImagePaths[0]); | ||
|
||
$my_collage = imagecreatetruecolor($width, $height); | ||
imagejpeg($my_collage, $destImagePath); // Transfer immage to destImagePath with returns the image to core | ||
imagedestroy($my_collage); // Destroy the created collage in memory | ||
break; | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters