Feat: correct colors and add text
This commit is contained in:
parent
5962194741
commit
7c928f3249
10 changed files with 84 additions and 65 deletions
|
@ -10,7 +10,7 @@ async fn handler() -> impl axum::response::IntoResponse {
|
|||
context.set_source_rgba(0.0, 0.0, 0.0, 0.0);
|
||||
context.fill().unwrap();
|
||||
|
||||
polygon::draw_polygon_of_polygons((50.0, 50.0), 65.0, 6, &context, false).unwrap();
|
||||
polygon::draw_polygon_of_polygons((50.0, 50.0), 65.0, 6, &context).unwrap();
|
||||
|
||||
let mut data: Vec<u8> = Vec::new();
|
||||
surface.write_to_png(&mut data).unwrap();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use axum::{extract::Query, routing::get, Router};
|
||||
use cairo::{Context, Format, ImageSurface};
|
||||
use rust_embed::RustEmbed;
|
||||
use serde::{de, Deserialize};
|
||||
|
||||
use crate::{color::Color, polygon, SharedState};
|
||||
|
@ -29,11 +30,33 @@ struct ImageProperties {
|
|||
#[serde(default = "default_as_false")]
|
||||
#[serde(deserialize_with = "deserialize_bool")]
|
||||
dark_mode: bool,
|
||||
#[serde(default = "default_as_false")]
|
||||
#[serde(deserialize_with = "deserialize_bool")]
|
||||
text: bool,
|
||||
background_color: Option<Color>,
|
||||
}
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "images"]
|
||||
struct ImageFiles;
|
||||
|
||||
fn get_surface_and_logo_coordiates(properties: &ImageProperties) -> (ImageSurface, (f64, f64)) {
|
||||
if properties.text {
|
||||
let image = ImageFiles::get("Makerlab.png").unwrap();
|
||||
(
|
||||
ImageSurface::create_from_png(&mut image.data.as_ref()).unwrap(),
|
||||
(604.0, 432.0),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
ImageSurface::create(Format::ARgb32, 400, 400).unwrap(),
|
||||
(200.0, 200.0),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
async fn handler(Query(properties): Query<ImageProperties>) -> impl axum::response::IntoResponse {
|
||||
let surface = ImageSurface::create(Format::ARgb32, 400, 400).unwrap();
|
||||
let (surface, logo_coordinates) = get_surface_and_logo_coordiates(&properties);
|
||||
let context = Context::new(&surface).unwrap();
|
||||
|
||||
if let Some(c) = properties.background_color {
|
||||
|
@ -44,14 +67,8 @@ async fn handler(Query(properties): Query<ImageProperties>) -> impl axum::respon
|
|||
|
||||
context.paint().unwrap();
|
||||
|
||||
polygon::draw_polygon_of_segmented_polygons(
|
||||
(200.0, 200.0),
|
||||
200.0,
|
||||
6,
|
||||
&context,
|
||||
properties.dark_mode,
|
||||
)
|
||||
.unwrap();
|
||||
polygon::draw_polygon_of_segmented_polygons(logo_coordinates, 148.0, 67.0, 6, &context)
|
||||
.unwrap();
|
||||
|
||||
let mut data: Vec<u8> = Vec::new();
|
||||
surface.write_to_png(&mut data).unwrap();
|
||||
|
|
|
@ -9,7 +9,7 @@ use rust_embed::{EmbeddedFile, RustEmbed};
|
|||
use crate::SharedState;
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "static"]
|
||||
#[folder = "web"]
|
||||
struct StaticFiles;
|
||||
|
||||
async fn static_files(uri: Uri) -> impl IntoResponse {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue