From d0d324ede91589d1e49a9a0728e5e5408262697b Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Thu, 25 Jun 2026 02:22:34 +1000 Subject: Added the ability to request arbitrary thumbnail ratios --- Services/MediaService.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Services/MediaService.cs b/Services/MediaService.cs index 6019f3f..1cfc345 100644 --- a/Services/MediaService.cs +++ b/Services/MediaService.cs @@ -316,6 +316,22 @@ public class MediaService : IMediaService { if(height > image.Height) height = (int) image.Height; + // Crop the image if a different aspect ratio is specified + if(width is not null && height is not null) { + double requestedRatio = (double) width / (double) height; + double currentRatio = (double) image.Width / (double) image.Height; + + double w = image.Width; + double h = image.Height; + + if(requestedRatio < currentRatio) + w = w / currentRatio * requestedRatio; + if(requestedRatio > currentRatio) + h = h / requestedRatio * currentRatio; + + image.Extent((uint) w, (uint) h, Gravity.Center); + } + image.Thumbnail((uint) (width ?? -1), (uint) (height ?? -1)); image.Write(thumbPath, MagickFormat.Jpeg); -- cgit v1.3