[][src]Trait iconwriter::Icon

pub trait Icon where
    Self: Sized
{ type Key: AsSize + Send + Sync; pub fn with_capacity(capacity: usize) -> Self;
pub fn len(&self) -> usize;
pub fn add_entry<F: FnMut(&DynamicImage, u32) -> Result<DynamicImage>>(
        &mut self,
        filter: F,
        source: &Image,
        key: Self::Key
    ) -> Result<(), IconError<Self::Key>>;
pub fn write<W: Write>(&mut self, w: &mut W) -> Result<()>; pub fn new() -> Self { ... }
pub fn add_entries<F: FnMut(&DynamicImage, u32) -> Result<DynamicImage>, I: IntoIterator<Item = Self::Key>>(
        &mut self,
        filter: F,
        source: &Image,
        keys: I
    ) -> Result<(), IconError<Self::Key>> { ... }
pub fn save<P: AsRef<Path>>(&mut self, path: &P) -> Result<()> { ... } }

A generic representation of an icon encoder.

Associated Types

Loading content...

Required methods

pub fn with_capacity(capacity: usize) -> Self[src]

Constructs a new, empty Icon with the specified capacity. The capacity argument designates the number of entries that will be allocated.

Example

let icon = Ico::with_capacity(5);

pub fn len(&self) -> usize[src]

Returns the number of entries contained in the icon.

pub fn add_entry<F: FnMut(&DynamicImage, u32) -> Result<DynamicImage>>(
    &mut self,
    filter: F,
    source: &Image,
    key: Self::Key
) -> Result<(), IconError<Self::Key>>
[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.
  • key Information on the target entry.

Return Value

  • Returns Err(IconError::AlreadyIncluded(_)) if the icon already contains an entry associated with key.
  • Returns Err(IconError::Resample(_)) if the resampling filter provided in the filter argument fails produces results of dimensions other than the ones specified by key.
  • Otherwise returns Ok(()).

Example

use iconwriter::{Ico, Image, Icon, IconError};
  
fn example() -> Result<(), IconError> {
    let icon = Ico::new();
    let src = Image::open("image.svg")?;

    icon.add_entry(resample::linear, &img, 32)
}

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

Writes the contents of the icon to w.

Example

use iconwriter::favicon::Favicon;
use std::{io, fs::File};
  
fn example() -> io::Result<()> {
    let icon = Favicon::new();

    /* Process the icon */

    let file = File::create("out.icns")?;
    icon.write(file)
}
Loading content...

Provided methods

pub fn new() -> Self[src]

Creates a new icon.

Example

let icon = Ico::new();

pub fn add_entries<F: FnMut(&DynamicImage, u32) -> Result<DynamicImage>, I: IntoIterator<Item = Self::Key>>(
    &mut self,
    filter: F,
    source: &Image,
    keys: I
) -> Result<(), IconError<Self::Key>>
[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.
  • keys A container for the information on the target entries.

Return Value

  • Returns Err(IconError::AlreadyIncluded(_)) if the icon already contains an entry associated with any of the items of keys.
  • Returns Err(IconError::Resample(_)) if the resampling filter provided in the filter argument fails or produces results of dimensions other than the ones specified by the items of keys.
  • Otherwise returns Ok(()).

Example

use iconwriter::{Icns, Image, Icon, IconError};
  
fn example() -> Result<(), IconError> {
    let icon = Icns::new();
    let src = Image::open("image.svg")?;

    icon.add_entries(
        resample::linear,
        &src,
        vec![32, 64, 128]
    )
}

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::favicon::Favicon;
use std::{io, fs::File};
  
fn example() -> io::Result<()> {
    let icon = Favicon::new();

    /* Process the icon */

    icon.save("./output/")
}
Loading content...

Implementors

impl Icon for Favicon[src]

type Key = Key

impl Icon for Icns[src]

type Key = Key

impl Icon for Ico[src]

type Key = Key

Loading content...