Skip to content
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
29 changes: 27 additions & 2 deletions api/applyEffects.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,39 @@
}

if (!$vars['isCollage'] || $vars['editSingleCollage']) {
// apply filter
// apply filter (optionally downscale first for performance)
if ($vars['imageFilter'] !== null && $vars['imageFilter'] !== ImageFilterEnum::PLAIN) {
$originalWidth = imagesx($imageResource);
$originalHeight = imagesy($imageResource);
$filterResource = $imageResource;

$filterProcessSize = intval($config['filters']['process_size'] ?? 0);
if ($filterProcessSize > 0 && ($originalWidth > $filterProcessSize || $originalHeight > $filterProcessSize)) {
$downscaled = $imageHandler->resizeImage($imageResource, $filterProcessSize);
if ($downscaled instanceof \GdImage) {
$filterResource = $downscaled;
}
}

try {
ImageUtility::applyFilter($vars['imageFilter'], $imageResource);
ImageUtility::applyFilter($vars['imageFilter'], $filterResource);
$imageHandler->imageModified = true;
} catch (\Exception $e) {
throw new \Exception('Error applying image filter.');
}

if ($filterResource !== $imageResource) {
$imageResource = $filterResource;
// Maybe we want this later or configurable, will take some time to process upscale again
// Upscale back to original size
// $restored = $imageHandler->resizeImage($filterResource, $originalWidth, $originalHeight);
// if ($restored instanceof \GdImage) {
// if ($filterResource instanceof \GdImage) {
// unset($filterResource);
// }
// $imageResource = $restored;
// }
}
}

if ($config['picture']['flip'] !== 'off') {
Expand Down
24 changes: 22 additions & 2 deletions assets/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const photoBooth = (function () {
chromaFile = '',
currentCollageFile = '',
imgFilter = config.filters.defaults,
isProcessingEffects = false,
command,
startTime,
endTime,
Expand All @@ -91,7 +92,7 @@ const photoBooth = (function () {
photoboothTools.console.log('Timeout for auto reload cleared.');

if (!api.takingPic) {
photoboothTools.console.logDev('Timeout for auto reload set to' + timeToLive + ' milliseconds.');
photoboothTools.console.logDev('Timeout for auto reload set to ' + timeToLive + ' milliseconds.');
timeOut = setTimeout(function () {
photoboothTools.reloadPage();
}, timeToLive);
Expand Down Expand Up @@ -154,6 +155,12 @@ const photoBooth = (function () {
}
};

const setFiltersEnabled = (enabled) => {
isProcessingEffects = !enabled;
filternav.css('pointer-events', enabled ? '' : 'none');
filternav.toggleClass('filters--disabled', !enabled);
};

api.stopPreviewAndCaptureFromVideo = () => {
if (config.preview.camTakesPic) {
if (photoboothPreview.stream) {
Expand Down Expand Up @@ -811,6 +818,7 @@ const photoBooth = (function () {
setTimeout(function () {
api.cheese.destroy();
api.shutter.destroy();
setFiltersEnabled(true);

loaderMessage.empty();
loaderButtonBar.empty();
Expand Down Expand Up @@ -850,6 +858,10 @@ const photoBooth = (function () {

api.processPic = function (result) {
startTime = new Date().getTime();
loader.addClass('stage--active');
startPage.removeClass('stage--active');
resultPage.removeClass('stage--active');
setFiltersEnabled(false);
loaderMessage.html(
'<i class="' +
config.icons.spinner +
Expand Down Expand Up @@ -881,10 +893,13 @@ const photoBooth = (function () {
style: api.photoStyle
},
success: (data) => {
setFiltersEnabled(true);
photoboothTools.console.log(api.photoStyle + ' processed', data);
endTime = new Date().getTime();
totalTime = endTime - startTime;
photoboothTools.console.logDev('Processing ' + api.photoStyle + ' took ' + totalTime + 'ms');
photoboothTools.console.logDev(
'Processing ' + api.photoStyle + ' took ' + totalTime + 'ms for filter `' + imgFilter + '`'
);
photoboothTools.console.logDev('Images:', data.images);

if (config.get_request.processed) {
Expand All @@ -901,6 +916,7 @@ const photoBooth = (function () {
}
},
error: (jqXHR, textStatus) => {
setFiltersEnabled(true);
api.errorPic({
error: 'Request failed: ' + textStatus
});
Expand Down Expand Up @@ -1360,6 +1376,10 @@ const photoBooth = (function () {
});

$('.sidenav-list-item[data-filter]').on('click', function () {
if (isProcessingEffects) {
photoboothTools.console.logDev('Ignoring filter click: processing in progress.');
return;
}
$('.sidenav').find('.sidenav-list-item--active').removeClass('sidenav-list-item--active');
$(this).addClass('sidenav-list-item--active');

Expand Down
4 changes: 4 additions & 0 deletions assets/sass/components/_sidenav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
height: var(--sidenav-close-height);
border: none;
line-height: 1;
padding: 0;
display: inline-flex;
align-items: center;
justify-content: center;

&:hover {
background: var(--highlight-color);
Expand Down
11 changes: 11 additions & 0 deletions lib/configsetup.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,17 @@
'options' => ImageFilterEnum::cases(),
'value' => $config['filters']['defaults'],
],
'filters_process_size' => [
'view' => 'expert',
'type' => 'range',
'name' => 'filters[process_size]',
'placeholder' => $defaultConfig['filters']['process_size'],
'value' => $config['filters']['process_size'],
'range_min' => 0,
'range_max' => 5000,
'range_step' => 50,
'unit' => 'px',
],
'filters_disabled' => [
'view' => 'expert',
'type' => 'multi-select',
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@
"manual:pictures:filters_defaults": "Wählen Sie einen Bildfilter, der standardmäßig nach der Aufnahme angewendet wird.",
"manual:pictures:filters_disabled": "Wählen Sie Filter aus, die aus den verfügbaren Bildfiltern entfernt werden.",
"manual:pictures:filters_enabled": "Wenn diese Option aktiviert ist, kann der Benutzer nach dem Aufnehmen eines Bildes einen Bildfilter auswählen.",
"manual:pictures:filters_process_size": "Bilder vor dem Filter auf diese maximale Breite/Höhe verkleinern, um die Verarbeitung zu beschleunigen. Auf 0 setzen, um zu deaktivieren.",
"manual:pictures:picture_allow_delete": "Wenn diese Option aktiviert ist, können Bilder direkt nach der Aufnahme auf der Ergebnisseite gelöscht werden.",
"manual:pictures:picture_cheese_time": "Legen Sie eine Zeit fest zur Anzeige von \"Cheeeeeeeese!\" nach dem Countdown.",
"manual:pictures:picture_cntdwn_time": "Legen Sie Ihre Countdown-Zeit fest.",
Expand Down Expand Up @@ -740,6 +741,7 @@
"pictures:filters_defaults": "Standardbildfilter",
"pictures:filters_disabled": "Deaktivierte Bildfilter",
"pictures:filters_enabled": "Bildfilter erlauben",
"pictures:filters_process_size": "Filter-Verarbeitungsgröße",
"pictures:picture_allow_delete": "Löschen des Bildes erlauben",
"pictures:picture_cheese_time": "Lächeln Timer:",
"pictures:picture_cntdwn_time": "Countdown Timer:",
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@
"manual:pictures:filters_defaults": "Choose an image filter which is applied by default after taking a picture.",
"manual:pictures:filters_disabled": "Choose filters which get removed from the available image filters.",
"manual:pictures:filters_enabled": "If enabled, users can choose an image filter after taking a picture.",
"manual:pictures:filters_process_size": "Downscale images to this maximum width/height before applying filters to speed up processing. Set to 0 to disable.",
"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.",
Expand Down Expand Up @@ -744,6 +745,7 @@
"pictures:filters_defaults": "Default image filter",
"pictures:filters_disabled": "Disabled image filters",
"pictures:filters_enabled": "Allow image filter",
"pictures:filters_process_size": "Filter processing size",
"pictures:picture_allow_delete": "Allow deletion of the image",
"pictures:picture_cheese_time": "Cheese timer:",
"pictures:picture_cntdwn_time": "Countdown timer:",
Expand Down
10 changes: 10 additions & 0 deletions src/Configuration/Section/FilterConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ public static function getNode(): NodeDefinition
})
->end()
->end()
->integerNode('process_size')
->info('Downscale images to this maximum width/height before applying filters to speed up processing. Set to 0 to disable.')
->defaultValue(0)
->min(0)
->max(5000)
->beforeNormalization()
->ifString()
->then(function (string $value): int { return intval($value); })
->end()
->end()
->arrayNode('disabled')
->enumPrototype()
->values(ImageFilterEnum::cases())
Expand Down
Loading