I have created this as cron job: nextcloud_scripts/nextcloud-preview.sh at master · GAS85/nextcloud_scripts · GitHub
Not shure if commented part still actual for newer Gallery app.
It is also to de executed from the CLI, because it could take a lot of time to generate previews first time (it took me around 3 days to generate previews to all XXX Gb of jpgs.