feat: backward compat with 80x80 icons
Added backwards compatibility with older versions expecting 80x80 icons with 8px padding
This commit is contained in:
parent
8e4e5dcf63
commit
37ef12f5c7
2 changed files with 15 additions and 2 deletions
|
@ -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)
|
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)
|
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)
|
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)
|
cache_key - string - Technically this can have any name. The server does not interpret this at all. Useful for cache busting. (default: none)
|
||||||
Example:
|
Example:
|
||||||
/icons/apple.png?scale=2&background=FF0000&discord_compatibility
|
/icons/apple.png?scale=2&background=FF0000&discord_compatibility
|
||||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -7,11 +7,11 @@ use resvg::{
|
||||||
usvg,
|
usvg,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mod constants;
|
||||||
mod handlers;
|
mod handlers;
|
||||||
mod http;
|
mod http;
|
||||||
mod icons;
|
mod icons;
|
||||||
mod threads;
|
mod threads;
|
||||||
mod constants;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("luciders starting...");
|
println!("luciders starting...");
|
||||||
|
@ -172,6 +172,18 @@ fn main() {
|
||||||
|
|
||||||
icon_string = icon_string.replace("currentColor", &svg_stroke);
|
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
|
// Rendering
|
||||||
let tree = match usvg::Tree::from_str(&icon_string, &usvg::Options::default()) {
|
let tree = match usvg::Tree::from_str(&icon_string, &usvg::Options::default()) {
|
||||||
Ok(tree) => tree,
|
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) {
|
let mut pixmap = match Pixmap::new(length, length) {
|
||||||
Some(pixmap) => pixmap,
|
Some(pixmap) => pixmap,
|
||||||
|
|
Loading…
Reference in a new issue