Encode an RGB image buffer to PNG bytes.
(image: &image::ImageBuffer<image::Rgb<u8>, Vec<u8>>)
| 14 | |
| 15 | /// Encode an RGB image buffer to PNG bytes. |
| 16 | fn encode_png(image: &image::ImageBuffer<image::Rgb<u8>, Vec<u8>>) -> Vec<u8> { |
| 17 | let dynamic_image = DynamicImage::ImageRgb8(image.clone()); |
| 18 | let mut png_bytes = Vec::new(); |
| 19 | let mut cursor = Cursor::new(&mut png_bytes); |
| 20 | dynamic_image |
| 21 | .write_to(&mut cursor, ImageFormat::Png) |
| 22 | .unwrap(); |
| 23 | png_bytes |
| 24 | } |
| 25 | |
| 26 | // ── Legacy image endpoint (/api/v1/image) ── |
| 27 |