pub struct ImageEngine { /* private fields */ }
Expand description
Engine for rendering rgba images to ascii text
source
: DynamicImageedge_map
: TODO: implement Edge detection methods
Implementations§
Source§impl ImageEngine
impl ImageEngine
Sourcepub fn new(source: DynamicImage) -> Self
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
: constructedDynamicImage
Sourcepub fn from_slice(source: &[u8]) -> Result<Self, Box<dyn Error>>
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
Sourcepub fn render_to_text(
&self,
writer: &mut dyn Write,
alpha_threshold: u8,
width: Option<u32>,
height: Option<u32>,
) -> Result<()>
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 implementsio::Write
alpha_threshold
: Lowest possible alpha value for ascii text to be renderedwidth
: New width of the ascii textheight
: New height of the ascii text
Sourcepub fn get_ascii_as_string(
&self,
alpha_threshold: u8,
width: Option<u32>,
height: Option<u32>,
) -> String
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 renderedwidth
: New width of the ascii textheight
: New height of the ascii text
Auto Trait Implementations§
impl Freeze for ImageEngine
impl RefUnwindSafe for ImageEngine
impl Send for ImageEngine
impl Sync for ImageEngine
impl Unpin for ImageEngine
impl UnwindSafe for ImageEngine
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