How to encode multiple pictures in a single .ico file? - Ico Encoding
I'm trying to create a function which takes a &Vec<RgbaImage> and saves them as a single .ico file in a given path: &String. Here's what I've got so far:
fn ico(bufs: &Vec<RgbaImage>, path: &String) -> Result<String, io::Error> {
match fs::File::create(path) {
Ok(file) => {
let mut output = ico::ICOEncoder::new(file);
for buf in bufs {
let (w, h) = buf.dimensions();
if let Err(err) = output.encode(&buf.clone().into_raw(), w, h, ColorType::RGBA(8)) {
return Err(err);
}
}
Ok(path.clone())
},
Err(err) => Err(err)
}
}
Is there a way to do it?
I don't think that is currently possible. We'd be open to a pull request to add the feature though
I ran into this same issue today and I ended up copy and pasting the encoder into my project and making it work for multiple images. I'll try to send a PR later, though I also think it'd be cool if the encoder took an externally encoded png, just so it could first be run through something like oxipng. Maybe it's just me having too much fun with this stuff, but having a <1kb favicon with 16x16, 32x32, 192x192 and 256x256 variants when most encoders give you a 16x16 and 32x32 4kb favicon is awesome :smile: