[][src]Trait iconwriter::Icon

pub trait Icon {
    pub fn new() -> Self;
pub fn add_entry<F: FnMut(&SourceImage, Size) -> Result<RgbaImage>>(
        &mut self,
        filter: F,
        source: &SourceImage,
        size: Size
    ) -> Result<()>;
pub fn add_entries<F: FnMut(&SourceImage, Size) -> Result<RgbaImage>, I: IntoIterator<Item = Size>>(
        &mut self,
        filter: F,
        source: &SourceImage,
        sizes: I
    ) -> Result<()>;
pub fn write<W: Write>(&mut self, w: &mut W) -> Result<()>; }

A generic representation of an icon encoder.

Required methods

pub fn new() -> Self[src]

Creates a new icon.

Example

let icon = Ico::new();

pub fn add_entry<F: FnMut(&SourceImage, Size) -> Result<RgbaImage>>(
    &mut self,
    filter: F,
    source: &SourceImage,
    size: Size
) -> Result<()>
[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

use iconwriter::*;
  
fn main() -> iconwriter::Result<()> {
    let icon = Ico::new();
 
    match SourceImage::from_path("image.svg") {
        Some(img) => icon.add_entry(resample::linear, &img, 32),
        None      => Ok(())
    }
}

pub fn add_entries<F: FnMut(&SourceImage, Size) -> Result<RgbaImage>, I: IntoIterator<Item = Size>>(
    &mut self,
    filter: F,
    source: &SourceImage,
    sizes: I
) -> Result<()>
[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

use iconwriter::*;
  
fn main() -> iconwriter::Result<()> {
    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 write<W: Write>(&mut self, w: &mut W) -> Result<()>[src]

Writes the contents of the icon to w.

Example

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

Implementors

impl Icon for Icns[src]

impl Icon for Ico[src]

impl Icon for PngSequence[src]

Loading content...