async fn img_gen0(req: HttpRequest) -> Result<impl Responder> {
let data = req.uri().path().split("/").skip(3).next().unwrap();
let cursor = make_png(32, 32, 16, percent_decode_str(&data).into_iter().borrow_mut())?;
- println!("{:?}", &cursor);
Ok(HttpResponse::build(StatusCode::OK)
.content_type("image/png")
.body(cursor.into_inner()))
async fn img_pgen0(req: HttpRequest, canvas0: web::Data<Arc<Mutex<Option<Canvas>>>>) -> Result<impl Responder> {
let data = req.uri().path().split("/").skip(3).next().unwrap();
let mut cursor = Cursor::new(Vec::new());
- let tdim_x = 32;
- let tdim_y = 32;
- {
+ let scale = 16;
+ let tdim_x = 32 * scale;
+ let tdim_y = 32 * scale;
+ let img: RgbImage = {
let mut canvas_option = &mut *canvas0.lock().unwrap();
let canvas = canvas_option.take();
let canvas = rgb_encode_to_canvas(canvas.expect("Canvas doesn't exist!"), percent_decode_str(&data).into_iter().borrow_mut())?;
- to_imageresult(write_buffer_with_format(&mut cursor, &canvas.img, tdim_x, tdim_y, ColorType::Rgb8, Png))?;
- canvas_option.insert(canvas);
- }
+ canvas_option.insert(canvas).img.clone()
+ };
+ let img = resize(&img, tdim_x, tdim_y, FilterType::Nearest);
+ to_imageresult(write_buffer_with_format(&mut cursor, &img, tdim_x, tdim_y, ColorType::Rgb8, Png))?;
Ok(HttpResponse::build(StatusCode::OK)
.content_type("image/png")
.body(cursor.into_inner()))