From: MegaBrutal Date: Fri, 24 Jun 2022 20:55:45 +0000 (+0200) Subject: Put red pixels from data X-Git-Url: http://git.megabrutal.com/?p=litoprism.git;a=commitdiff_plain;h=9fa2bd778193b10edecc013ff8bf1afbb9ed04e8 Put red pixels from data --- diff --git a/src/main.rs b/src/main.rs index e4d6ac7..bab5da7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,9 +41,18 @@ async fn greet(name: web::Path) -> impl Responder { #[get("/gen/{data}")] async fn img_gen(data: web::Path) -> Result { let mut cursor = Cursor::new(Vec::new()); - let img: RgbImage = ImageBuffer::new(512, 512); - to_imageresult(write_buffer_with_format(&mut cursor, &img, 512, 512, ColorType::Rgb8, Png))?; - Ok(cursor.into_inner().customize().insert_header(("content-type", "image/png"))) + let mut img: RgbImage = ImageBuffer::new(128, 128); + let mut pixels = img.pixels_mut(); + + for c in data.chars() { + let mut p = pixels.next().unwrap(); + p.0 = [c as u8, 0, 0]; + } + + to_imageresult(write_buffer_with_format(&mut cursor, &img, 128, 128, ColorType::Rgb8, Png))?; + Ok(HttpResponse::build(StatusCode::OK) + .content_type("image/png") + .body(cursor.into_inner())) } #[actix_web::main] // or #[tokio::main]