Skip to content

Commit

Permalink
Apply tag overlays onto avatars again, had been dropped when switchin…
Browse files Browse the repository at this point in the history
…g to ImageSharp. Also, licensing notice about ImageSharp in Readme
  • Loading branch information
RedFlames committed Apr 20, 2024
1 parent 1ce1f42 commit ab24076
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
21 changes: 20 additions & 1 deletion CelesteNet.Server.FrontendModule/RCEPs/RCEPPublic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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`:
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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)

0 comments on commit ab24076

Please sign in to comment.