From ab240763e2e60095be725cf593a8a87ec7f047a4 Mon Sep 17 00:00:00 2001 From: RedFlames Date: Sun, 21 Apr 2024 01:52:37 +0200 Subject: [PATCH] Apply tag overlays onto avatars again, had been dropped when switching to ImageSharp. Also, licensing notice about ImageSharp in Readme --- .../RCEPs/RCEPPublic.cs | 21 ++++++++++++++++++- README.md | 8 ++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CelesteNet.Server.FrontendModule/RCEPs/RCEPPublic.cs b/CelesteNet.Server.FrontendModule/RCEPs/RCEPPublic.cs index 4bb30e0a..794d9d5a 100644 --- a/CelesteNet.Server.FrontendModule/RCEPs/RCEPPublic.cs +++ b/CelesteNet.Server.FrontendModule/RCEPs/RCEPPublic.cs @@ -133,7 +133,7 @@ public static void DiscordOAuth(Frontend f, HttpRequestEventArgs c) { using (avatarOrig) using (Image avatarScale = avatarOrig.Clone(x => x.Resize(64, 64, sampler: KnownResamplers.Lanczos3))) - using (Image avatarFinal = avatarOrig.Clone(x => x.Resize(64, 64, sampler: KnownResamplers.Lanczos3).ApplyRoundedCorners(1.0f))) { + using (Image avatarFinal = avatarScale.Clone(x => x.ApplyRoundedCorners(1.0f).ApplyTagOverlays(f, info))) { using (Stream s = f.Server.UserData.WriteFile(uid, "avatar.orig.png")) avatarScale.SaveAsPng(s); @@ -151,6 +151,25 @@ public static void DiscordOAuth(Frontend f, HttpRequestEventArgs c) { }); } + private static IImageProcessingContext ApplyTagOverlays(this IImageProcessingContext context, Frontend f, BasicUserInfo info) { + + context.SetGraphicsOptions(new GraphicsOptions() { + Antialias = true, + AlphaCompositionMode = PixelAlphaCompositionMode.SrcOver + }); + + foreach (string tagName in info.Tags) { + using Stream? asset = f.OpenContent($"frontend/assets/tags/{tagName}.png", out _, out _, out _); + if (asset == null) + continue; + + using Image tag = Image.Load(asset); + context.DrawImage(tag, 1.0f); + } + + return context; + } + // These functions copied from ImageSharp's Samples code -- https://github.com/SixLabors/Samples/blob/main/ImageSharp/AvatarWithRoundedCorner/Program.cs // This method can be seen as an inline implementation of an `IImageProcessor`: diff --git a/README.md b/README.md index 90d6472f..94ee56f9 100644 --- a/README.md +++ b/README.md @@ -21,4 +21,10 @@ It lets you join levels together with your friends or complete strangers, even j ## How do I play on CelesteNet? First, make sure that you've installed [Everest (mod loader) via Olympus (mod manager)][everest-site]. -Click on the "Download CelesteNet" button above, then click the "1-CLICK INSTALL" button on the latest version. \ No newline at end of file +Click on the "Download CelesteNet" button above, then click the "1-CLICK INSTALL" button on the latest version. + +--- + +#### License notice + +The CelesteNet.Server.FrontendModule project/module uses [ImageSharp](https://github.com/SixLabors/ImageSharp/) under Apache 2.0 license terms per [Six Labors Split License 1.0](https://github.com/SixLabors/ImageSharp/blob/main/LICENSE) \ No newline at end of file