icon_baker 0.1.3

A simple solution for generating .ico and .icns icons.
Documentation

IconBaker (LIB)

Crate API Minimum rustc version

A simple solution for generating .ico and .icns icons. This crate serves as IconBaker CLI's internal library.

Basic usage

use icon_baker::prelude*;

const n_entrie: usize = 1;

fn main() {
    // Creating the icon
    let mut icon = Icon::ico(n_entries);

    // Importing the source image
    let source_image = SourceImage::from_file("img.jpg").unwrap();

    // Configuring the entry
    let opts = IconOptions::new(
        vec![(32, 32), (64, 64)] /* 32x32 and 64x64 icon */,
        ResamplingFilter::Linear /* Iterpolate the image */,
        Crop::Square             /* Square image */
    );

    // Adding the entry
    icon.add_entry(opts, &source_image).unwrap();
}

It is important to note that although the Icon returned by the Icon::ico, Icon::icns, Icon::png_sequece and Icon::new methods has the capacity specified, the Icon will have zero entries.

For an explanation of the difference between length and capacity, see Capacity and reallocation.

Writing to files

use icon_baker::prelude*;
use std::fs::File;

const n_entrie: usize = ...;

fn main() {
    let mut icon = Icon::ico(n_entries);

    /* Process the icon */

    if let Ok(&file) = File::create("myfile.ico") {
        match icon.write(file) {
            Ok(()) => println!("File 'myfile.ico' saved!"),
            Err(_) => println!("An error occured ;-;")
        }
    }
}