INNER CODE UNIT · Rust
get_bytes_webp
silvia-odwyer/photon · crate/src/lib.rs:234
pub fn get_bytes_webp(&self) -> Vec<u8> {
// write_to owns the lossy/lossless encoder choice, so one clone is
// the floor here.
let img = ImageRgba8(
image::ImageBuffer::from_raw(
self.width,
self.height,
self.raw_pixels.clone(),
)
.unwrap(),
);
let mut buffer = vec![];
img.write_to(
&mut Cursor::new(&mut buffer),
image::ImageOutputFormat::WebP,
)
.unwrap();
buffer