#icons #image #ico #codec #pixel #fs-file

yanked icodec

A library for encoding and decoding ICO image files

Uses old Rust 2015

0.1.0-alpha.3 Mar 18, 2020
0.1.0-alpha.2 Feb 20, 2020
0.1.0-alpha.1 Dec 21, 2019

#7 in #ico

MIT license

24KB
418 lines

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.

Usage

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

#![allow(overflowing_literals)]

use std::io;
use icodec::{resample, encode::{IcoEncoder, Encode, Save}, Image, Icon};

fn example() -> io::Result<()> {
    // Initialize the icon
    let mut ico = IcoEncoder::new();
 
    // Add a single icon
    let image = Image::open("example.png")?;
    ico.add_icon(resample::linear, &image, Icon(32, 32))?;
 
    // Add multiple icons
    ico.add_icons(
        resample::linear,
        &image,
        vec![Icon(64, 64), Icon(256, 256)]
    )?;
 
    // Save the icon to disk
    ico.save(&"~/example.ico")?;
    Ok(())
}

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

Traits and types to assist in decoding ICO files.

Example

#![allow(overflowing_literals)]

use std::{io, fs::File};
use icodec::{decode::{IcoDecoder, Decode}, Image, Icon};

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

    // Attempt to parse the file
    let ico = IcoDecoder::read(file)?;
 
    // Loop trought the icons of the icon
    // in an arbitraty order
    for (icon, image) in &ico {
        // Do something . . .
    }
    
    // Querying the icon for a particularly
    // sized image
    if let Some(image) = ico.get(&Icon(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 😃

Dependencies

~14MB
~261K SLoC