Overlay text on an image, and get the resulting bytes

Here's the code from that other thread, modified to write to a Vec<u8> instead of a file:

let mut output: Vec<u8> = Vec::new();
{
    let mut encoder = png::Encoder::new(&mut output, info.width, info.height);
    encoder.set(png::ColorType::RGBA).set(png::BitDepth::Eight);
    
    let mut writer = encoder.write_header().unwrap();
    writer.write_image_data(&data).expect("Failed to write the image data");
}
// now `output` contains the PNG image.