Crate API Minimum rustc version Downloads License

A pure Rust library for encoding and decoding ICO image files. This is a fork of rust-ico.

Overview

An ICO file (.ico) stores a collection of small images of different sizes and color depths (up to 256x256 pixels each). Individial images within the file can be encoded in either BMP or PNG format. ICO files are typically used for website favicons and for Windows application icons.

Examples

Joining multiple images into an ICO file can be accomplished with the encode::IcoEncoder struct:

```rust

![allow(overflowing_literals)]

extern crate ico;

use ico::{resample, encode::{IcoEncoder, Encode, Save}, Image, Size};

fn main() -> io::Result<()> { // Initialize the icon let mut icon = IcoEncoder::new();

// Add a single entry
let image = Image::open("example.png")?;
icon.add_entry(resample::linear, &image, Size(32, 32))?;

// Add multiple entries
icon.add_entries(
    resample::linear,
    &image,
    vec![Size(64, 64), Size(256, 256)]
)?;

// Save the icon to disk
icon.save("~/example.ico")

} ```

Likewise, decoding ICO files can be done via the decode::IcoDecoder struct:

```rust

![allow(overflowing_literals)]

extern crate ico;

use std::fs::File; use ico::{decode::{IcoDecoder, Decode}, Image, Size};

fn main() -> io::Result<()> { // Open the source file let file = File::open("~/example.ico")?;

// Attempt to parse the file
let icon = IcoDecoder::read(file)?;

// Loop trought the entries of the icon
// in an arbitraty order
for (size, image) in icon {
    // Do something . . .
}

// Querying the icon for a particularly
// sized image
if let Some(image) = icon.get(&Size(256, 256)) {
    // Do something . . .
}

Ok(())

} ```

Supported Image Formats

| Format | Supported? | |--------|------------------------------------------------------------------------| | png | All supported color types | | jpeg | Baseline and progressive | | gif | Yes | | bmp | Yes | | webp | Lossy(Luma channel only) | | svg | Static SVG Full 1.1 |

Build Requirements

Icodec relies on harfbuzz_rs, wich means CMake is required to be installed for it build.

License

Icodec is made available under the MIT License.

This is a fork of rust-ico. As such, it conforms to it's original licensing terms.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be licensed as above, without any additional terms or conditions.

Feel free to help out! Contributions are welcomed 😃