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

Commit

Permalink
general: make database optional, read images from images folder if di…
Browse files Browse the repository at this point in the history
…sabled

Change-Id: I7dea6d8ea35eff98f7919aa0010db7432b43fc65
  • Loading branch information
andi34 committed Mar 10, 2021
1 parent 478c603 commit f89982c
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 11 deletions.
6 changes: 4 additions & 2 deletions api/applyEffects.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,10 @@
imagedestroy($imageResource);

// insert into database
if ($_POST['style'] !== 'chroma' || ($_POST['style'] === 'chroma' && $config['live_keying']['show_all'] === true)) {
appendImageToDB($file);
if ($config['database']['enabled']) {
if ($_POST['style'] !== 'chroma' || ($_POST['style'] === 'chroma' && $config['live_keying']['show_all'] === true)) {
appendImageToDB($file);
}
}

// Change permissions
Expand Down
17 changes: 15 additions & 2 deletions api/chromakeying/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@
require_once '../../lib/resize.php';

if ($config['picture']['naming'] === 'numbered') {
$images = getImagesFromDB();
if ($config['database']['enabled']) {
$images = getImagesFromDB();
} else {
$directory = $config['foldersAbs']['images'];
$dh = opendir($directory);

while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
closedir($dh);
$images = preg_grep('/\.(jpg|jpeg|JPG|JPEG)$/i', $files);
}
$img_number = count($images);
$files = str_pad(++$img_number, 4, '0', STR_PAD_LEFT);
$name = $files . '.jpg';
Expand Down Expand Up @@ -44,7 +55,9 @@
imagedestroy($imageResource);

// insert into database
appendImageToDB($file);
if ($config['database']['enabled']) {
appendImageToDB($file);
}

// Change permissions
chmod($filename_photo, octdec($picture_permissions));
Expand Down
4 changes: 3 additions & 1 deletion api/deletePhoto.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
}
}

deleteImageFromDB($file);
if ($config['database']['enabled']) {
deleteImageFromDB($file);
}

echo json_encode([
'success' => true,
Expand Down
13 changes: 12 additions & 1 deletion api/takePic.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,18 @@ function takePicture($filename) {
if (!empty($_POST['file']) && preg_match('/^[a-z0-9_]+\.jpg$/', $_POST['file'])) {
$name = $_POST['file'];
} elseif ($config['picture']['naming'] === 'numbered') {
$images = getImagesFromDB();
if ($config['database']['enabled']) {
$images = getImagesFromDB();
} else {
$directory = $config['foldersAbs']['images'];
$dh = opendir($directory);

while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
closedir($dh);
$images = preg_grep('/\.(jpg|jpeg|JPG|JPEG)$/i', $files);
}
$img_number = count($images);
$files = str_pad(++$img_number, 4, '0', STR_PAD_LEFT);
$name = $files . '.jpg';
Expand Down
1 change: 1 addition & 0 deletions config/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
// control time in milliseconds until Photobooth reloads automatically
$config['picture']['time_to_live'] = '90000';
$config['picture']['preview_before_processing'] = true;
$config['database']['enabled'] = true;
$config['database']['file'] = 'db';


Expand Down
16 changes: 14 additions & 2 deletions gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,19 @@
exit(json_encode($resp));
}

$images = getImagesFromDB();
if ($config['database']['enabled']) {
$images = getImagesFromDB();
} else {
$directory = $config['foldersAbs']['images'];
$dh = opendir($directory);

while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
closedir($dh);
$images = preg_grep('/\.(jpg|jpeg|JPG|JPEG)$/i', $files);
}

$imagelist = ($config['gallery']['newest_first'] === true) ? array_reverse($images) : $images;
?>
<!DOCTYPE html>
Expand Down Expand Up @@ -101,4 +113,4 @@
<script src="node_modules/@andreasremdt/simple-translator/dist/umd/translator.min.js"></script>
<script type="text/javascript" src="resources/js/i18n.js"></script>
</body>
</html>
</html>
14 changes: 13 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@
require_once('lib/db.php');
require_once('lib/filter.php');

$images = getImagesFromDB();
if ($config['database']['enabled']) {
$images = getImagesFromDB();
} else {
$directory = $config['foldersAbs']['images'];
$dh = opendir($directory);

while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
closedir($dh);
$images = preg_grep('/\.(jpg|jpeg|JPG|JPEG)$/i', $files);
}

$imagelist = ($config['gallery']['newest_first'] === true) ? array_reverse($images) : $images;

if ($config['ui']['style'] === 'modern') {
Expand Down
6 changes: 6 additions & 0 deletions lib/configsetup.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@
'name' => 'picture[preview_before_processing]',
'value' => $config['picture']['preview_before_processing'],
],
'database_enabled' => [
'view' => 'expert',
'type' => 'checkbox',
'name' => 'database[enabled]',
'value' => $config['database']['enabled'],
],
'database_file' => [
'view' => 'expert',
'type' => 'input',
Expand Down
13 changes: 12 additions & 1 deletion livechroma.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@
require_once('lib/config.php');
require_once('lib/db.php');

$images = getImagesFromDB();
if ($config['database']['enabled']) {
$images = getImagesFromDB();
} else {
$directory = $config['foldersAbs']['images'];
$dh = opendir($directory);

while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
closedir($dh);
$images = preg_grep('/\.(jpg|jpeg|JPG|JPEG)$/i', $files);
}
$imagelist = ($config['gallery']['newest_first'] === true) ? array_reverse($images) : $images;

if ($config['ui']['style'] === 'modern') {
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"gallery_no_image": "The gallery is still empty. Take some pictures!",
"general": "General",
"general:adminpanel_view": "Admin Options",
"general:database_enabled": "Use database for images",
"general:database_file": "Database file name",
"general:dev_enabled": "Dev-Mode",
"general:dev_error_messages": "Show error messages",
Expand Down Expand Up @@ -212,6 +213,7 @@
"manual:gallery:pswp_tapToToggleControls": "If enabled, the visibility of controls / buttons is switched by tapping.",
"manual:gallery:pswp_zoomEl": "If enabled, PhotoSwipe zoom button is visible inside gallery.",
"manual:general:adminpanel_view": "Allows to set different views in the admin panel with more (Expert View) or less (Basic View) options accessible",
"manual:general:database_enabled": "If enabled, images will be added to a database which is used by the gallery. If disabled, gallery will read the images folder for images - this could reduce the performance.",
"manual:general:database_file": "Name of the database file.",
"manual:general:dev_enabled": "Enables development mode. Sample pictures will be used instead taking a picture.",
"manual:general:dev_error_messages": "If enabled real error messages are shown on error.",
Expand Down
13 changes: 12 additions & 1 deletion slideshow/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@
require_once('../lib/db.php');
require_once('../lib/filter.php');

$images = getImagesFromDB();
if ($config['database']['enabled']) {
$images = getImagesFromDB();
} else {
$directory = $config['foldersAbs']['images'];
$dh = opendir($directory);

while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
closedir($dh);
$images = preg_grep('/\.(jpg|jpeg|JPG|JPEG)$/i', $files);
}
$imagelist = array_reverse($images);

?>
Expand Down

0 comments on commit f89982c

Please sign in to comment.