From 37ef12f5c7b1310c84f608de6d304480e8410c97 Mon Sep 17 00:00:00 2001 From: Compositr Date: Mon, 4 Nov 2024 22:00:41 +1100 Subject: [PATCH] feat: backward compat with 80x80 icons Added backwards compatibility with older versions expecting 80x80 icons with 8px padding --- src/constants.rs | 1 + src/main.rs | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index f69aa5b..0ea7e74 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -11,6 +11,7 @@ GET /icons/[icon].png - Get an icon rendered in PNG format background - hex - Set the background color in hex WITHOUT the hashtag (e.g. FFFFFF) (default: transparent) stroke_colour - string - Set the stroke color for the SVG icon, any CSS color WITH the hashtag (default: currentColor) discord_compatibility - boolean - Set padding to 8px for Discord compatibility. Typically for use in embed author icons as these have a circle clip applied by Discord. Overrides padding if set. (default: false) + backwards_compatibility - boolean - Sets padding to 8px, and scale to 3x for backwards compatibility with older versions of Lucide server (so they are 80x80 again). (default: false) cache_key - string - Technically this can have any name. The server does not interpret this at all. Useful for cache busting. (default: none) Example: /icons/apple.png?scale=2&background=FF0000&discord_compatibility diff --git a/src/main.rs b/src/main.rs index e5f9a61..61c6577 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,11 +7,11 @@ use resvg::{ usvg, }; +mod constants; mod handlers; mod http; mod icons; mod threads; -mod constants; fn main() { println!("luciders starting..."); @@ -172,6 +172,18 @@ fn main() { icon_string = icon_string.replace("currentColor", &svg_stroke); + let mut backwards_compatibility = false; + match req.url.query.get("backwards_compatibility") { + Some(_) => { + backwards_compatibility = true; + // Icons were 80x80 plus 8px of padding; Icons start at 24x24 now so: 80 - 8 = 72, 72 / 24 = 3 therefore scale is 3x. + scale = 3; + padding = 8; + + } + None => {} + } + // Rendering let tree = match usvg::Tree::from_str(&icon_string, &usvg::Options::default()) { Ok(tree) => tree, @@ -182,7 +194,7 @@ fn main() { }; - let length = 24 * scale + padding; + let length = if backwards_compatibility { 80 } else { 24 * scale + padding }; let mut pixmap = match Pixmap::new(length, length) { Some(pixmap) => pixmap,