The Free Software Media System - Server Backend & API
Pick blurhash sizes depending on image aspect ratio
Vasilyf575415e0b61
diff --git a/Jellyfin.Drawing.Skia/SkiaEncoder.cs b/Jellyfin.Drawing.Skia/SkiaEncoder.csindex 7ab0a54dfd..ccd501214e 100644--- a/Jellyfin.Drawing.Skia/SkiaEncoder.cs+++ b/Jellyfin.Drawing.Skia/SkiaEncoder.cs@@ -241,14 +241,20 @@ namespace Jellyfin.Drawing.Skiathrow new ArgumentNullException(nameof(path));}- if (!File.Exists(path))+ var dims = GetImageSize(path);+ if (dims.Width <= 0 || dims.Height <= 0){- throw new FileNotFoundException("File not found", path);+ // empty image does not have any blurhash+ return string.Empty;}- // Use 4 vertical and 4 horizontal components of DCT of the image.+ // We want tiles to be as close to square as possible, and to *mostly* keep under 16 tiles for performance.+ // One tile is (width / xComp) x (height / yComp) pixels, which means that ideally yComp = xComp * height / width.// See more at https://github.com/woltapp/blurhash/#how-do-i-pick-the-number-of-x-and-y-components- return BlurHashEncoder.Encode(4, 4, path);+ float xComp = MathF.Sqrt(16.0f * dims.Width / dims.Height);+ float yComp = xComp * dims.Height / dims.Width;++ return BlurHashEncoder.Encode(Math.Min((int)xComp + 1, 9), Math.Min((int)yComp + 1, 9), path);}private static bool HasDiacritics(string text)