icodec

Crates.ioicodec
lib.rsicodec
version0.1.0-alpha.3
sourcesrc
created_at2019-12-21 16:03:37.879927
updated_at2020-03-18 14:42:31.988962
descriptionA library for encoding and decoding ICO image files
homepage
repositoryhttps://github.com/GarkGarcia/iko
max_upload_size
id191222
size24,293
Gark Garcia (GarkGarcia)

documentation

README

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 😃

Commit count: 0

cargo fmt