Struct ImageEngine

Source
pub struct ImageEngine { /* private fields */ }
Expand description

Engine for rendering rgba images to ascii text

  • source: DynamicImage
  • edge_map: TODO: implement Edge detection methods

Implementations§

Source§

impl ImageEngine

Source

pub fn new(source: DynamicImage) -> Self

Construct a new engine from an owned dynamic image

§Usage
    
use std::error::Error;
use rustascii::{image, image_proc::ImageEngine};

fn main() -> Result<(), Box<dyn Error>> {
    let source = image::open("/")?;
    let engine = ImageEngine::new(source);
    // Do your stuff with the engine
    Ok(())
}
  • source: constructed DynamicImage
Source

pub fn from_slice(source: &[u8]) -> Result<Self, Box<dyn Error>>

Construct a new engine from a slice of bytes

§Usage
    use rustascii::{image_proc::ImageEngine};
    use std::error::Error;

    fn main() -> Result<(), Box<dyn Error>> {
        let source = include_bytes!("your image path");
        let engine = ImageEngine::from_slice()?;
        // Do stuff with the engine
        Ok(())
    }
  • source: a slice of bytes
Source

pub fn render_to_text( &self, writer: &mut dyn Write, alpha_threshold: u8, width: Option<u32>, height: Option<u32>, ) -> Result<()>

Process the image, with scaling, and write the output to a writer.

Note that either width or height must be Some(value)

§Usage

Here is a simple example writing to stdout.

    use rustascii::{image_proc::ImageEngine};
    use std::{error::Error, io::stdout};

    fn main() -> Result<(), Box<dyn Error>> {
        let source = include_bytes!("your-path");
        let engine = ImageEngine::from_slice(source)?;

        let mut writer = stdout(); // stdout implements io::Write!

        // If only one of the axis is set,
        // the image aspect ratio will be preserved
        engine.render_to_text(&mut writer, 0, Some(128), None)?;
        Ok(())
    }

You can also do some more advance with writer, like TcpStream, or File

    use rustascii::{image_proc::ImageEngine};
    use std::{error::Error, io::stdout};

    fn main() -> Result<(), Box<dyn Error>> {
        let source = include_bytes!("your-path");
        let engine = ImageEngine::from_slice(source)?;

        let mut file_writer = fs::File::create_new("your-new-file")?;

        // If only one of the axis is set,
        // the image aspect ratio will be preserved
        engine.render_to_text(&mut file_writer, 0, Some(128), None)?;
        Ok(())
    }
  • writer: Some thing that implements io::Write
  • alpha_threshold: Lowest possible alpha value for ascii text to be rendered
  • width: New width of the ascii text
  • height: New height of the ascii text
Source

pub fn get_ascii_as_string( &self, alpha_threshold: u8, width: Option<u32>, height: Option<u32>, ) -> String

Get all of the content as a string, using this is not recommended, using render_to_text should covered almost all cases.

  • alpha_threshold: Lowest possible alpha value for ascii text to be rendered
  • width: New width of the ascii text
  • height: New height of the ascii text

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.