Optimizing Slow Image Previews in Nextcloud

Marko BurazinMarko Burazin
4 min read

If you're self hosting Nextcloud and enjoy maintaining a digital gallery, you've likely run into the headache that is image preview generation. Instead of providing handy thumbnails for quick browsing, Nextcloud generates previews of an unwieldy 4096px by default 🤯. This might sound practical at first—previews you can click on for a full-size view—but it ends up being more trouble than it's worth.

I'm not the only one who thinks this choice is odd. Many people on the Nextcloud forum are frustrated by it. There's also a related issue on GitHub that the maintainers closed without actually fixing.

In this blog, I’ll detail the underlying issues of this default approach and, more importantly, guide you through a solution that will spare your resources and your sanity.

The Problem: Oversized Previews Lead to Performance Issues

Image previews should be a quick glance at what a photo contains, not a heavy-duty, full-resolution copy. With Nextcloud's default setting, generating previews takes an unexpectedly long time, consuming CPU, memory, and excessive disk space. On a fresh Nextcloud installation, the process of generating these previews can cause severe server slowdowns for large photo collections, rendering your setup unresponsive. For HEIF images, the previews themselves can even occupy more space than the originals—an absurd situation for any user trying to manage storage efficiently.

The Default Photos App Complication

Switching to smaller previews seems like the easy fix, right? In theory, yes.

Let’s start by redefining previews to be a maximum of 1024x1024 pixels with JPEG quality dialed down to 60% by running the following Nexcloud CLI commands:

occ config:system:set preview_max_x --value="1024" --type=integer  
occ config:system:set preview_max_y --value="1024" --type=integer
occ config:system:set jpeg_quality --value="60" --type=integer
occ config:app:set preview jpeg_quality --value="60" --type=integer

This tweak boosts preview generation speed and storage efficiency. Unfortunately, the Photos app bundled with Nextcloud doesn’t distinguish between thumbnails and full-resolution previews when you click on an image. This means in our case, instead of displaying the original photo, it enlarges the smaller preview, resulting in blurry, grainy images that ruin the viewing experience.

Finding a Solution: Introducing the Memories App

The key to overcoming this limitation is to ditch the default Photos app and employ an alternative: the Memories app, available directly from the Nextcloud app store. This app is a beacon of hope, allowing for proper handling of images by showing the full-resolution photo when you click for a larger view. Not only does it use the preview generator efficiently, but it also optimizes thumbnail loading, making your gallery experience smoother and more enjoyable.

Steps for a Seamless Transition:

  1. Install the Memories App: Head to the Nextcloud app store, find Memories, and install it.

  2. Install Preview Generator: Memories leverages the Preview Generator app. Ensure this is also installed and configured for optimal performance.

  3. Configure the Settings:

    • Navigate to the Memories app settings within the Nextcloud "Administration settings."

    • Set preview generation to a maximum of 1024px width, aligning it with your previous adjustments.

    • In the "File support" section, tailor the configuration to the file types you're working with to ensure previews are generated accurately.

  4. Adjust Photo Viewer Settings:

    • Opt for "Always load high resolution image" in the Photo Viewer’s settings. This ensures that when you click an image thumbnail, the full-resolution original will display immediately.

  5. Now use the Memories app in Nextcloud instead of “Photos” to browse and manage your gallery!


By following these steps, you transform your Nextcloud gallery from a lagging, resource-intensive setup into a streamlined, efficient image repository.

Make sure to review the Memories app documentation for additional important configurations that are essential to set up. While I won't cover those details here to maintain the focus of this blog post, feel free to ask any questions in the comments section.

Conclusion

In conclusion, while Nextcloud’s default image preview behavior might complicate your digital gallery management, the Memories app offers a more robust solution. By implementing the strategies outlined above, you'll not only enhance your server performance but also improve the user experience dramatically. Say goodbye to laggy image previews and hello to a more intuitive image browsing experience.

I hope this guide helps clear up the clutter in your Nextcloud instance and restores your joy in managing digital photos!

0
Subscribe to my newsletter

Read articles from Marko Burazin directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Marko Burazin
Marko Burazin