From 568afc981e5c3048af2d0fd331cf265dc69d580b Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 2 Jun 2025 02:54:32 +0800 Subject: [PATCH] :sparkles: Skip compress animated image --- DysonNetwork.Sphere/Storage/FileService.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/DysonNetwork.Sphere/Storage/FileService.cs b/DysonNetwork.Sphere/Storage/FileService.cs index a18a82b..88fbc8a 100644 --- a/DysonNetwork.Sphere/Storage/FileService.cs +++ b/DysonNetwork.Sphere/Storage/FileService.cs @@ -176,6 +176,16 @@ public class FileService( if (contentType.Split('/')[0] == "image") { + // Skip compression for animated image types + var animatedMimeTypes = new[] { "image/gif", "image/apng", "image/webp", "image/avif" }; + if (animatedMimeTypes.Contains(contentType)) + { + logger.LogInformation("File {fileId} is an animated image (MIME: {mime}), skipping WebP conversion.", fileId, contentType); + var tempFilePath = Path.Join(Path.GetTempPath(), $"{TempFilePrefix}#{file.Id}"); + result.Add((tempFilePath, string.Empty)); + return; + } + file.MimeType = "image/webp"; using var vipsImage = NetVips.Image.NewFromFile(ogFilePath);