[][src]Trait iconwriter::Icon

pub trait Icon<E: AsRef<u32> + Debug + Eq> {
    pub fn new() -> Self;
pub fn add_entry<F: FnMut(&SourceImage, u32) -> DynamicImage>(
        &mut self,
        filter: F,
        source: &SourceImage,
        entry: E
    ) -> Result<(), Error<E>>;
pub fn write<W: Write>(&mut self, w: &mut W) -> Result<()>; pub fn add_entries<F: FnMut(&SourceImage, u32) -> DynamicImage, I: IntoIterator<Item = E>>(
        &mut self,
        filter: F,
        source: &SourceImage,
        entries: I
    ) -> Result<(), Error<E>> { ... }
pub fn save<P: AsRef<Path>>(&mut self, path: &P) -> Result<()> { ... } }

A generic representation of an icon encoder.

Required methods

pub fn new() -> Self[src]

Creates a new icon.

Example

This example is not tested
let icon = Ico::new();

pub fn add_entry<F: FnMut(&SourceImage, u32) -> DynamicImage>(
    &mut self,
    filter: F,
    source: &SourceImage,
    entry: E
) -> Result<(), Error<E>>
[src]

Adds an individual entry to the icon.

Arguments

  • filter The resampling filter that will be used to re-scale source.
  • source A reference to the source image this entry will be based on.
  • size The target size of the entry in pixels.

Return Value

  • Returns Err(Error::InvalidSize(_)) if the dimensions provided in the size argument are not supported.
  • Returns Err(Error::Image(ImageError::DimensionError)) if the resampling filter provided in the filter argument produces results of dimensions other than the ones specified by size.
  • Otherwise return Ok(()).

Example

This example is not tested
use iconwriter::{Ico, SourceImage, Icon};
use iconwriter::Error as IconError;
  
fn example() -> Result<(), IconError> {
    let icon = Ico::new();
 
    match SourceImage::from_path("image.svg") {
        Some(img) => icon.add_entry(resample::linear, &img, 32),
        None      => Ok(())
    }
}

pub fn write<W: Write>(&mut self, w: &mut W) -> Result<()>[src]

Writes the contents of the icon to w.

Example

This example is not tested
use iconwriter::*;
use std::{io, fs::File};
  
fn example() -> io::Result<()> {
    let icon = PngSequence::new();
 
    /* Process the icon */
 
    let file = File::create("out.icns")?;
    icon.write(file)
}
Loading content...

Provided methods

pub fn add_entries<F: FnMut(&SourceImage, u32) -> DynamicImage, I: IntoIterator<Item = E>>(
    &mut self,
    filter: F,
    source: &SourceImage,
    entries: I
) -> Result<(), Error<E>>
[src]

Adds a series of entries to the icon.

Arguments

  • filter The resampling filter that will be used to re-scale source.
  • source A reference to the source image this entry will be based on.
  • size A container for the target sizes of the entries in pixels.

Return Value

  • Returns Err(Error::InvalidSize(_)) if the dimensions provided in the size argument are not supported.
  • Returns Err(Error::Image(ImageError::DimensionError)) if the resampling filter provided in the filter argument produces results of dimensions other than the ones specified by size.
  • Otherwise return Ok(()).

Example

This example is not tested
use iconwriter::{Icns, SourceImage, Icon};
use iconwriter::Error as IconError;
  
fn example() -> Result<(), IconError> {
    let icon = Icns::new();
 
    match SourceImage::from_path("image.svg") {
        Some(img) => icon.add_entries(
            resample::linear,
            &img,
            vec![32, 64, 128]
        ),
        None => Ok(())
    }
}

pub fn save<P: AsRef<Path>>(&mut self, path: &P) -> Result<()>[src]

Writes the contents of the icon to a file on disk.

Example

use iconwriter::*;
use std::{io, fs::File};
  
fn example() -> io::Result<()> {
    let icon = Ico::new();
 
    /* Process the icon */
 
    icon.save("./output/out.ico")
}
Loading content...

Implementors

impl Icon<Entry> for Icns[src]

impl Icon<Entry> for Ico[src]

impl Icon<NamedEntry> for PngSequence[src]

Loading content...