[][src]Crate iconwriter

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 Iconiic'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.

IconWriter 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 iconwriter::{Ico, Image, Icon, IconError};
 
fn example() -> Result<(), IconError> {
    let icon = Ico::new();
    let src = Image::open("image.svg")?;
    icon.add_entry(resample::linear, &img, 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 iconwriter::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 iconwriter::favicon::Favicon;
use std::{io, fs::File};
  
fn example() -> io::Result<()> {
    let icon = Favicon::new();

    /* Process the icon */

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

Re-exports

pub extern crate image;
pub extern crate resvg;
pub use resvg::raqote;
pub use resvg::usvg;

Modules

encode

A collection of functions to assist in encoding images in commonly used file formats.

favicon

Structs for encoding favicons.

icns

Structs for encoding .icns files.

ico

Structs for encoding .ico files.

resample

A collection of commonly used resampling filters.

Structs

XmlOptions

An XML writing options.

Enums

IconError

The error type for operations of the Icon trait.

Image

A uniun type for raster and vector graphics.

ResampleError

The error type for resampling operations.

XmlIndent

An XML node indention.

Traits

AsSize

A trait for types that represent the dimesions of an icon.

Icon

A generic representation of an icon encoder.