From: MegaBrutal Date: Thu, 14 Jul 2022 23:40:00 +0000 (+0200) Subject: Use actual image dimensions X-Git-Url: http://git.megabrutal.com/?a=commitdiff_plain;h=d22c64d4d6ec36ede4f4ff0834266604b3ffef66;p=litoprism.git Use actual image dimensions --- diff --git a/src/main.rs b/src/main.rs index 9d1bd44..68a4034 100644 --- a/src/main.rs +++ b/src/main.rs @@ -187,14 +187,14 @@ async fn img_pgen0(req: HttpRequest, canvas0: web::Data let data = req.uri().path().split("/").skip(3).next().unwrap(); let mut cursor = Cursor::new(Vec::new()); let scale = 16; - let tdim_x = 32 * scale; - let tdim_y = 32 * scale; let img: RgbImage = { let canvas_option = &mut *canvas0.lock().unwrap(); let canvas = canvas_option.take().ok_or(CanvasError::NotExists)?; let canvas = rgb_encode_to_canvas(canvas, percent_decode_str(&data).into_iter().borrow_mut())?; canvas_option.insert(canvas).img.clone() }; + let (tdim_x, tdim_y) = img.dimensions(); + let (tdim_x, tdim_y) = (tdim_x * scale, tdim_y * scale); 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)