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

feature: allow to flip image after taken #209

Merged
merged 1 commit into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions api/applyEffects.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@
$image_filter = $_POST['filter'];
}

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);
Expand Down
2 changes: 2 additions & 0 deletions config/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
$config['picture']['no_cheese'] = false;
// control time for cheeeeese! in milliseconds
$config['picture']['cheese_time'] = '1000';
// possible flip values: 'off', 'horizontal', 'vertical', 'both'
$config['picture']['flip'] = 'off';
$config['picture']['rotation'] = '0';
$config['picture']['polaroid_effect'] = false;
$config['picture']['polaroid_rotation'] = '0';
Expand Down
16 changes: 16 additions & 0 deletions lib/collage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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']);

function createCollage($srcImagePaths, $destImagePath) {
if (!is_array($srcImagePaths) || count($srcImagePaths) !== COLLAGE_LIMIT) {
Expand All @@ -27,6 +28,21 @@ function createCollage($srcImagePaths, $destImagePath) {
$white = 16777215;
$black = 0;

if (PICTURE_FLIP !== 'off') {
for ($i = 0; $i < COLLAGE_LIMIT; $i++) {
$imageResource = imagecreatefromjpeg($srcImagePaths[$i]);
if (PICTURE_FLIP === 'horizontal') {
imageflip($imageResource, IMG_FLIP_HORIZONTAL);
} elseif (PICTURE_FLIP === 'vertical') {
imageflip($imageResource, IMG_FLIP_VERTICAL);
} elseif (PICTURE_FLIP === 'both') {
imageflip($imageResource, IMG_FLIP_BOTH);
}
imagejpeg($imageResource, $srcImagePaths[$i], $quality);
imagedestroy($imageResource);
}
}

list($width, $height) = getimagesize($srcImagePaths[0]);
if ($width > $height) {
$landscape = true;
Expand Down
13 changes: 13 additions & 0 deletions lib/configsetup.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,19 @@
'range_step' => 250,
'unit' => 'milliseconds',
],
'picture_flip' => [
'view' => 'advanced',
'type' => 'select',
'name' => 'picture[flip]',
'placeholder' => $defaultConfig['picture']['flip'],
'options' => [
'off' => 'off',
'horizontal' => 'horizontal',
'vertical' => 'vertical',
'both' => 'horizontal + vertical',
],
'value' => $config['picture']['flip'],
],
'picture_rotation' => [
'view' => 'advanced',
'type' => 'input',
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
"manual:pictures:picture_allow_delete": "If enabled pictures can be deleted on result page directly after they have been taken.",
"manual:pictures:picture_cheese_time": "Set a time to display \"Cheeeeeeeese!\" after the countdown.",
"manual:pictures:picture_cntdwn_time": "Set your countdown time.",
"manual:pictures:picture_flip": "Choose if your picture is flipped after taken.",
"manual:pictures:picture_frame": "Enter the path of the frame which is applied to your picture after taking it.",
"manual:pictures:picture_keep_original": "If enabled, original images will be kept inside tmp folder.",
"manual:pictures:picture_key": "Specify the key id to use that key to take a picture (e.g. 13 is the enter key). For example use <a href=\"https://keycode.info\" target=\"_blank\">https://keycode.info</a> to find out the key id.",
Expand Down Expand Up @@ -348,6 +349,7 @@
"pictures:picture_allow_delete": "Allow deletion of the image",
"pictures:picture_cheese_time": "Cheeeeeeeese!-Timer:",
"pictures:picture_cntdwn_time": "Countdown timer:",
"pictures:picture_flip": "Flip image:",
"pictures:picture_frame": "Frame",
"pictures:picture_keep_original": "Keep original images in tmp folder",
"pictures:picture_key": "Key code which triggers a photo",
Expand Down