#[get("/gen/{data}")]
async fn img_gen(data: web::Path<String>) -> Result<impl Responder> {
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]