Crates.io | icodec |
lib.rs | icodec |
version | 0.1.0-alpha.3 |
source | src |
created_at | 2019-12-21 16:03:37.879927 |
updated_at | 2020-03-18 14:42:31.988962 |
description | A library for encoding and decoding ICO image files |
homepage | |
repository | https://github.com/GarkGarcia/iko |
max_upload_size | |
id | 191222 |
size | 24,293 |
A pure Rust library for encoding and decoding ICO image files. This is a fork of rust-ico.
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.
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.
#![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(())
}
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 |
Icodec relies on harfbuzz_rs
, wich means
CMake is required to be installed for it build.
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.
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 😃