#icon #ico #icns

icon_baker

A simple solution for encoding common icon file formats

32 releases (13 stable)

✓ Uses Rust 2018 edition

3.2.0 Oct 25, 2019
3.2.0-beta.2 Sep 23, 2019
2.2.0 Aug 29, 2019
1.3.1-beta Aug 12, 2019
0.1.3 Jun 9, 2019

#1 in #icon

Download history 79/week @ 2019-08-17 197/week @ 2019-08-24 101/week @ 2019-08-31 74/week @ 2019-09-07 82/week @ 2019-09-14 212/week @ 2019-09-21 68/week @ 2019-09-28 34/week @ 2019-10-05 4/week @ 2019-10-12 233/week @ 2019-10-19 402/week @ 2019-10-26 81/week @ 2019-11-02 140/week @ 2019-11-09 220/week @ 2019-11-16 226/week @ 2019-11-23

395 downloads per month
Used in 1 crate

Custom license

55KB
928 lines

IconBaker

Crate API Minimum rustc version Downloads License

A simple solution for encoding common icon file-formats, such as .ico, .icns and favicon.

This crate is mostly a wrapper for other libraries, unifying existing APIs into a single, cohesive interface. It serves as IconPie's internal library.

Overview

An icon consists of a map between keys and images. An entry is a key-value pair contained in an icon.

IconBaker simply automates the process of re-scaling images, creating entries and combining them into an icon.

Keys

Each icon format is associated with a particular key type, which determines how entries are labeled. Each key can only be associated with a single image.

For example, icon formats that only differentiate entries by the dimensions of their associated images are labeled by positive integers, such as the .ico and .icns file-formats.

On the other hand, icon formats that distinguish their entries by path, such as png sequeces and FreeDesktop icon themes , are labeled by path.

Note that, since the dimensions of the images contained in an entry are dictated by their associated entries, every key must be convertible to a positive integers. Therefore, all key types are required to implement AsRef<u32>.

Resampling

Pictures are scaled using resampling filters, which are represented by functions that take a source image and a size and return a re-scaled image.

This allows the users of this crate to provide their custom resampling filters. Common resampling filters are provided in the resample module.

Examples

General Usage

The Icon::add_entry can be used to automatically resample source images and converts them to entries in an icon.

use icon_baker::{ico::{Ico, Key}, Image, Icon, IconError};

fn example() -> Result<(), IconError> {
    let icon = Ico::new();
    let src = Image::open("image.svg")?;

    icon.add_entry(resample::linear, &img, Key(32))
}

Writing to Disk

Implementors of the Icon trait can be written to any object that implements io::Write with the Icon::write method.

use icon_baker::favicon::Favicon;
use std::{io, fs::File};
 
fn example() -> io::Result<()> {
    let icon = Favicon::new();

    // Process the icon ...

    let file = File::create("out.icns")?;
    icon.write(file)
}

Alternatively, icons can be directly written to a file on disk with Icon::save method.

use icon_baker::favicon::Favicon;
use std::{io, fs::File};
 
fn example() -> io::Result<()> {
    let icon = Favicon::new();

    /* Process the icon */

    icon.save("./output/")
}

Support

Icon Formats

These are the output formats IconBaker natively supports. Be aware that custom output types can be created using the Icon trait.

  • ico
  • icns
  • favicon

Icns Support

Icon Baker uses the icns crate for generating .icns files. The supported icon types are specified by the creators of such crate as follows:

OSType Description Supported?
ICON 32×32 1-bit entry No
ICN# 32×32 1-bit entry with 1-bit mask No
icm# 16×12 1-bit entry with 1-bit mask No
icm4 16×12 4-bit entry No
icm8 16×12 8-bit entry No
ics# 16×16 1-bit mask No
ics4 16×16 4-bit entry No
ics8 16x16 8-bit entry No
is32 16×16 24-bit entry Yes
s8mk 16x16 8-bit mask Yes
icl4 32×32 4-bit entry No
icl8 32×32 8-bit entry No
il32 32x32 24-bit entry Yes
l8mk 32×32 8-bit mask Yes
ich# 48×48 1-bit mask No
ich4 48×48 4-bit entry No
ich8 48×48 8-bit entry No
ih32 48×48 24-bit entry Yes
h8mk 48×48 8-bit mask Yes
it32 128×128 24-bit entry Yes
t8mk 128×128 8-bit mask Yes
icp4 16x16 32-bit png/jp2 entry png only
icp5 32x32 32-bit png/jp2 entry png only
icp6 64x64 32-bit png/jp2 entry png only
ic07 128x128 32-bit png/jp2 entry png only
ic08 256×256 32-bit png/jp2 entry png only
ic09 512×512 32-bit png/jp2 entry png only
ic10 512x512@2x "retina" 32-bit png/jp2 entry png only
ic11 16x16@2x "retina" 32-bit png/jp2 entry png only
ic12 32x32@2x "retina" 32-bit png/jp2 entry png only
ic13 128x128@2x "retina" 32-bit png/jp2 entry png only
ic14 256x256@2x "retina" 32-bit png/jp2 entry png only

Image Formats

IconBaker uses image for raster graphics manipulations and resvg with the raqote backend for svg rasterization. Note that raqote requires cmake to build.

Format Supported?
png All supported color types
jpeg Baseline and progressive
gif Yes
bmp Yes
ico Yes
tiff Baseline(no fax support), lzw, PackBits
webp Lossy(Luma channel only)
pnm pbm, pgm, ppm, standard pma
svg Static SVG Full 1.1

License

Licensed under MIT license(LICENSE-MIT or http://opensource.org/licenses/MIT).

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

~10MB
~186K SLoC