icns-rs

Easily create .icns files (Mac Icons) with this Rust library or the included CLI app.
Log | Files | Refs | LICENSE

commit 3249860ced966ec9a9589bf53ff17af23617f8fd
parent dc186d347eea7a5fc8d52a169382613709544cb0
Author: Jack Mordaunt <jackmordaunt@gmail.com>
Date:   Mon, 31 Dec 2018 12:00:28 +1300

[+] Example to show off usage of the encoder.

Diffstat:
Aexamples/convert_png.rs | 38++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+), 0 deletions(-)

diff --git a/examples/convert_png.rs b/examples/convert_png.rs @@ -0,0 +1,37 @@ +use clap::{App, Arg}; +use std::io::prelude::*; +use std::fs; +use image; +use icns::encode::Encoder; + +fn main() { + let matches = App::new("convert png to icns") + .version("0.1.0") + .author("Jack Mordaunt <jackmordaunt@gmail.com>") + .about("easily convert png to icns") + .arg(Arg::with_name("input") + .required(true) + .takes_value(true) + .short("i") + .help("path to input png image")) + .arg(Arg::with_name("output") + .required(true) + .takes_value(true) + .short("o") + .help("path to output icns image")) + .get_matches(); + let input = matches.value_of("input").unwrap(); + let output = matches.value_of("output").unwrap(); + let mut png: Vec<u8> = vec![]; + fs::File::open(&input) + .expect("opening input file") + .read_to_end(&mut png) + .expect("buffering input file"); + let png = image::load_from_memory(&png) + .expect("decoding png from buffer"); + let mut output = fs::File::create(&output) + .expect("creating output file"); + Encoder::new(&mut output) + .encode(&png) + .expect("encoding icns"); +} +\ No newline at end of file