Jellyfin is a self hosted media server that I’m using to catalogue my movie collection. The data is stored in a SQLite database, and for each movie added a poster is downloaded and stored.

The concept:

  • workout target file size
  • read the database for image file locations
  • with the now known target file size, and number of images, some thoughts
    • how many rows of images?
    • how many columns?
    • any padding or use all the space avaialble?
    • are the source images the same aspect ratio?
    • if there are not enough images to fill out a row, should the row be truncated?
  • anyway, resize the source posters and then use these to create a wallpaper…simple right!…

This project actually came up with a few mathematical issues, which was fun, such as calculating the width and height of a rectangle when you know only the area and aspect ratio:

area = width * height
area = width * 3 / 2 * width
area = width² * 3 / 2
area * 2 / 3 = width²
(area * 2 / 3) = width
thumbwidth = int(sqrt(targetarea / count * 2 / 3));

If for example the target width was calculated to be 27 pixels, at an aspect ration of 3:2 this would give a height of 27/2 * 3 = 40.5. You can’t have 40.5 pixels.

So reduce the width and check again.

if(thumbwidth % 2 != 0){ --thumbwidth;}

Although, on review I could rewrite this to a modulo operation.

Some sample configurations which result in zero padding when used:

Full width Full height Images Sample wallpaper
1920 1080 96  
1920 1080 864  
1920 1080 1536  
3840 2160 216 sample-three (7mb)
1080 2040 918 sample-one (8mb), sample-two (8mb)

Anyway, I packaged this all up into an AWK script I could run from WSL.