diff options
Diffstat (limited to 'Services/MediaService.cs')
| -rw-r--r-- | Services/MediaService.cs | 16 |
1 files changed, 16 insertions, 0 deletions
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); |
