feat: bg colour option
This commit is contained in:
parent
dd53cce7f6
commit
c5fa5fb07b
1 changed files with 22 additions and 0 deletions
22
src/main.rs
22
src/main.rs
|
@ -134,6 +134,27 @@ fn main() {
|
|||
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 mut pixmap = match Pixmap::new(length, length) {
|
||||
|
@ -142,6 +163,7 @@ fn main() {
|
|||
};
|
||||
|
||||
let mut pixmap_mut = pixmap.as_mut();
|
||||
pixmap_mut.fill(background);
|
||||
|
||||
resvg::render(
|
||||
&tree,
|
||||
|
|
Loading…
Reference in a new issue