pub struct IcnsEncoder { /* private fields */ }Expand description
The main encoder struct
Create a new encoder with IcnsEncoder::new()
Implementations§
Source§impl IcnsEncoder
impl IcnsEncoder
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new IcnsEncoder
Usage:
use icns_rs::{IcnsEncoder, IconFormats};
use image::open;
use std::fs::File;
use std::io::prelude::*;
// Open the image
let image = match open("512x512@2.png") {
Ok(image) => image,
Err(e) => {
println!("Error: {}", e);
std::process::exit(1);
}
};
// 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 ould not encode image");
std::process::exit(1);
}
};
// Write data to file
let mut file = match File::create("example.icns") {
Ok(file) => file,
Err(e) => {
println!("Error: {}", e);
std::process::exit(1);
}
};
match file.write_all(&data) {
Ok(_) => println!("Successfully wrote to file"),
Err(e) => {
println!("Error: {}", e);
std::process::exit(1);
}
};Examples found in repository?
examples/encode.rs (line 17)
6fn main() -> std::io::Result<()> {
7 // Open the image
8 let image = match open("example.png") {
9 Ok(image) => image,
10 Err(e) => {
11 println!("Error opening file: {}", e);
12 return Ok(());
13 }
14 };
15
16 // Create the encoder
17 let mut encoder = IcnsEncoder::new();
18
19 encoder.data(image);
20 encoder.formats(IconFormats::recommended());
21
22 // Encode the image
23 let data = match encoder.build() {
24 Ok(data) => data,
25 Err(e) => {
26 println!("Error encoding image: {}", e);
27 return Ok(());
28 }
29 };
30
31 // Write data to file
32 let mut file = File::create("example.icns")?;
33 file.write_all(&data)?;
34
35 Ok(())
36}Sourcepub fn data(&mut self, data: DynamicImage) -> &mut Self
pub fn data(&mut self, data: DynamicImage) -> &mut Self
Sets the image data. Encode a png and pass it as a DynamicImage.
Examples found in repository?
examples/encode.rs (line 19)
6fn main() -> std::io::Result<()> {
7 // Open the image
8 let image = match open("example.png") {
9 Ok(image) => image,
10 Err(e) => {
11 println!("Error opening file: {}", e);
12 return Ok(());
13 }
14 };
15
16 // Create the encoder
17 let mut encoder = IcnsEncoder::new();
18
19 encoder.data(image);
20 encoder.formats(IconFormats::recommended());
21
22 // Encode the image
23 let data = match encoder.build() {
24 Ok(data) => data,
25 Err(e) => {
26 println!("Error encoding image: {}", e);
27 return Ok(());
28 }
29 };
30
31 // Write data to file
32 let mut file = File::create("example.icns")?;
33 file.write_all(&data)?;
34
35 Ok(())
36}Sourcepub fn formats(&mut self, formats: Vec<IconFormats>) -> &mut Self
pub fn formats(&mut self, formats: Vec<IconFormats>) -> &mut Self
Sets the image formats to be encoded
Examples found in repository?
examples/encode.rs (line 20)
6fn main() -> std::io::Result<()> {
7 // Open the image
8 let image = match open("example.png") {
9 Ok(image) => image,
10 Err(e) => {
11 println!("Error opening file: {}", e);
12 return Ok(());
13 }
14 };
15
16 // Create the encoder
17 let mut encoder = IcnsEncoder::new();
18
19 encoder.data(image);
20 encoder.formats(IconFormats::recommended());
21
22 // Encode the image
23 let data = match encoder.build() {
24 Ok(data) => data,
25 Err(e) => {
26 println!("Error encoding image: {}", e);
27 return Ok(());
28 }
29 };
30
31 // Write data to file
32 let mut file = File::create("example.icns")?;
33 file.write_all(&data)?;
34
35 Ok(())
36}Sourcepub fn build(&self) -> Result<Box<[u8]>, String>
pub fn build(&self) -> Result<Box<[u8]>, String>
Encodes the image as an ICNS file
Examples found in repository?
examples/encode.rs (line 23)
6fn main() -> std::io::Result<()> {
7 // Open the image
8 let image = match open("example.png") {
9 Ok(image) => image,
10 Err(e) => {
11 println!("Error opening file: {}", e);
12 return Ok(());
13 }
14 };
15
16 // Create the encoder
17 let mut encoder = IcnsEncoder::new();
18
19 encoder.data(image);
20 encoder.formats(IconFormats::recommended());
21
22 // Encode the image
23 let data = match encoder.build() {
24 Ok(data) => data,
25 Err(e) => {
26 println!("Error encoding image: {}", e);
27 return Ok(());
28 }
29 };
30
31 // Write data to file
32 let mut file = File::create("example.icns")?;
33 file.write_all(&data)?;
34
35 Ok(())
36}Auto Trait Implementations§
impl Freeze for IcnsEncoder
impl RefUnwindSafe for IcnsEncoder
impl Send for IcnsEncoder
impl Sync for IcnsEncoder
impl Unpin for IcnsEncoder
impl UnwindSafe for IcnsEncoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more