Crates.io | icns-rs |
lib.rs | icns-rs |
version | 0.1.2 |
source | src |
created_at | 2023-07-06 08:58:11.904819 |
updated_at | 2023-07-16 19:57:20.459277 |
description | A library for reading and writing Apple Icon Image (.icns) files. |
homepage | https://github.com/JoshuaBrest/icns-rs |
repository | https://github.com/JoshuaBrest/icns-rs |
max_upload_size | |
id | 909691 |
size | 311,724 |
The ICNS format is a file format used by Apple to store icons for macOS applications. This crate provides a simple API for reading and (and soon)writing ICNS files.
Here's a simple example of how to read an ICNS file:
You can find this example in
examples/encode.rs
or run it with:cargo run --example encode
use std::fs::File;
use std::io::prelude::*;
use image::open;
use icns_rs::{IcnsEncoder, IconFormats};
fn main() -> std::io::Result<()> {
// Open the image
let image = match open("example.png") {
Ok(image) => image,
Err(e) => {
println!("Error opening file: {}", e);
return Ok(());
}
};
// Create the encoder
let mut encoder = IcnsEncoder::new();
encoder.data(image);
encoder.formats(IconFormats::recommended());
// Encode the image
let data = match encoder.build() {
Ok(data) => data,
Err(e) => {
println!("Error encoding image: {}", e);
return Ok(());
}
};
// Write data to file
let mut file = File::create("example.icns")?;
file.write_all(&data)?;
Ok(())
}
This project is licensed under the GPLv3 license. See the LICENSE file for more details.
Contributions are welcome! Feel free to open an issue or submit a pull request.
This project is heavily inspired by:
When I started building this, I didn't know there already was a ICNS lib for rust, but, after looking at it, it was not up to my standards because of the lack of ARGB, RGB, and, Mask support. I wanted to create a modern package that was easy to use and had a simple API. I also wanted to make sure that it was well documented and had a good test suite. I hope you enjoy using this package as much as I enjoyed making it!.