Previews jumping up as popcorn

Increase the gallery performance significantly by enabling the Preview Generator app. Start the Preview Generation and wait for its end – then edit the crontab to perform periodic thumbnail generations for newly created data and finally enjoy your previews as “jumping popcorn”! So let’s start…

Ensure your gallery app v. 17+ is enabled (switch to enabled apps)

and then enable the Preview Generator app: (navigate to Multimedia and enable the Preview Generator app):

Both apps, the Gallery 17.+ and the Preview Generator 1.0.6+ App, will appear as enabled apps in the Nextcloud Enabled App-Panel:

You could also enable both apps using Nextcloud CLI (Nextcloud Command Line Interface):

sudo -u www-data php /var/www/nextcloud/occ app:enable gallery && sudo -u www-data php /var/www/nextcloud/occ app:enable previewgenerator

The generation of previews will take a long time, that’s why i recommend using screen for running the following command in the background. If not already installed just run

apt install screen

first. To reduce the upcoming amount of new created preview files and with regards to your /var/www/nextcloud/config/config.php

your Nextcloud settings could look like:

'preview_max_x' => 1024,
'preview_max_y' => 768,
'preview_max_scale_factor' => 1,

Now edit two files manually:

vi /var/www/nextcloud/apps/previewgenerator/lib/Command/Generate.php


vi /var/www/nextcloud/apps/previewgenerator/lib/Command/PreGenerate.php

Substitute the red marked values accordingly to your current config.php settings:

$maxW = (int)$this->config->getSystemValue('preview_max_x', 512);
$maxH = (int)$this->config->getSystemValue('preview_max_y', 512);

$s = 512;
while ($s <= $maxW || $s <= $maxH) {
$this->sizes['square'][] = $s;
$s *= 2;

$w = 512;
while ($w <= $maxW) {
$this->sizes['width'][] = $w;
$w *= 2;

$h = 512;
while ($h <= $maxH) {
$this->sizes['height'][] = $h;
$h *= 2;

As a result only 2 files for each picture will be generated instead of many many more…¬† Then create a dedicated screen session

screen -S PreviewGeneration

to start the preview generation:

sudo -u www-data php /var/www/nextcloud/occ preview:generate-all

The duration depends of the amount of data … be patient and stay tuned! At least we edit crontab for the webuser to generate new thumbnails for new created data automatically e.g. every hour:

sudo crontab -u www-data -e

Add e.g. the following line:

@hourly php -f /var/www/nextcloud/occ preview:pre-generate >> /home/<ubuntuuser>/bkup/preview.log 2>&1
crontab -u www-data -l

The output should look similar to mine:

*/15 * * * * php -f /var/www/nextcloud/cron.php > /dev/null 2>&1
@hourly php -f /var/www/nextcloud/occ preview:pre-generate >> /home/<ubuntuuser>/bkup/preview.log 2>&1

Optimize your Nextcloud (a) from time to time and (b) regulary using a script


/usr/sbin/service nginx stop
sudo -u www-data php /var/www/nextcloud/occ db:add-missing-indices
sudo -u www-data php /var/www/nextcloud/occ db:convert-filecache-bigint
/usr/sbin/service nginx start

(infos: BigInt, missing indices)


vi /root/
redis-cli -s /var/run/redis/redis-server.sock <<EOF
sudo -u www-data php /var/www/nextcloud/occ files:scan --all
sudo -u www-data php /var/www/nextcloud/occ files:scan-app-data
exit 0

Save the script and mark it as executable

chmod +x /root/

Issue the script initially:


Add Nextcloud cronjobs for www-data and root

For www-data:

crontab -u www-data -e

Paste the following rows

*/15 * * * * php -f /var/www/nextcloud/cron.php > /dev/null 2>&1

For root:

crontab -e

Paste the follwoing rows:

5 1 * * * /root/ > /dev/null 2>&1

Carsten Rieger