feat: bg colour option

This commit is contained in:
Compositr 2024-11-02 12:34:16 +11:00
parent dd53cce7f6
commit c5fa5fb07b

View file

@ -134,6 +134,27 @@ fn main() {
None => {} None => {}
} }
let mut background = Color::TRANSPARENT;
match req.url.query.get("background") {
Some(background_str) => {
match u32::from_str_radix(&background_str, 16) {
Ok(background_val) => {
if background_val > 0xFFFFFF {
return Response::new(req, 400, Body::Static("Invalid background value. Background value must be a valid hex color 000000 - FFFFFF"));
}
let red = ((background_val >> 16) & 0xFF) as u8;
let green = ((background_val >> 8) & 0xFF) as u8;
let blue = (background_val & 0xFF) as u8;
background = Color::from_rgba8(red, green, blue, 255);
}
Err(_) => {
return Response::new(req, 400, Body::Static("Invalid background value. Background value must be a valid hex color"));
}
}
}
None => {}
}
let length = 24 * scale + padding; let length = 24 * scale + padding;
let mut pixmap = match Pixmap::new(length, length) { let mut pixmap = match Pixmap::new(length, length) {
@ -142,6 +163,7 @@ fn main() {
}; };
let mut pixmap_mut = pixmap.as_mut(); let mut pixmap_mut = pixmap.as_mut();
pixmap_mut.fill(background);
resvg::render( resvg::render(
&tree, &tree,