Skip to main content

ConversionOptions

Struct ConversionOptions 

Source
pub struct ConversionOptions {
    pub columns: Option<u32>,
    pub font_ratio: f32,
    pub luminance: u8,
    pub ascii_chars: String,
    pub output_mode: OutputMode,
}
Expand description

Options for ASCII conversion

Fields§

§columns: Option<u32>

Target width in characters (columns)

§font_ratio: f32

Font aspect ratio (width/height of character)

§luminance: u8

Luminance threshold (0-255) for transparency

§ascii_chars: String

ASCII character set to use (from darkest to lightest)

§output_mode: OutputMode

What output files to generate

Implementations§

Source§

impl ConversionOptions

Source

pub fn with_columns(self, columns: u32) -> Self

Create options with a specific width

Examples found in repository?
examples/simple_image.rs (line 13)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    // Create a converter with default configuration
9    let converter = AsciiConverter::new();
10
11    // Configure conversion options
12    let options = ConversionOptions::default()
13        .with_columns(100)
14        .with_font_ratio(0.5)
15        .with_luminance(20);
16
17    // Example 1: Convert image to ASCII file
18    let input = Path::new("resources/source.png");
19    let output = Path::new("example_output.txt");
20
21    if input.exists() {
22        println!("Converting {} to ASCII art...", input.display());
23        converter.convert_image(input, output, &options)?;
24        println!("✓ ASCII art saved to {}", output.display());
25    } else {
26        println!(
27            "Note: {} not found, skipping file conversion example",
28            input.display()
29        );
30    }
31
32    // Example 2: Convert image to string (no file)
33    if input.exists() {
34        println!("\nConverting image to string...");
35        let ascii_string = converter.image_to_string(input, &options)?;
36        println!(
37            "✓ Generated ASCII string ({} characters)",
38            ascii_string.len()
39        );
40        println!("\nFirst 500 characters:");
41        println!("{}", &ascii_string[..500.min(ascii_string.len())]);
42    }
43
44    // Example 3: Using presets
45    if input.exists() {
46        println!("\n\nUsing 'small' preset...");
47        let small_options = converter.options_from_preset("small")?;
48        let output_small = Path::new("example_output_small.txt");
49        converter.convert_image(input, output_small, &small_options)?;
50        println!("✓ Small ASCII art saved to {}", output_small.display());
51    }
52
53    Ok(())
54}
Source

pub fn with_font_ratio(self, font_ratio: f32) -> Self

Create options with a specific font ratio

Examples found in repository?
examples/simple_video.rs (line 23)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    // Create a converter
9    let converter = AsciiConverter::new();
10
11    // Configure video options
12    let video_opts = VideoOptions {
13        fps: 10,
14        start: Some("0".to_string()),
15        end: Some("2".to_string()), // Extract first 2 seconds
16        columns: 200,
17        extract_audio: false,
18        preprocess_filter: None,
19    };
20
21    // Configure conversion options
22    let conv_opts = ConversionOptions::default()
23        .with_font_ratio(0.5)
24        .with_luminance(20);
25
26    // Convert video
27    let input = Path::new("tests/video/input/test.mkv");
28    let output_dir = Path::new("example_video_output");
29
30    if input.exists() {
31        println!("Converting video to ASCII frames...");
32        println!("Input: {}", input.display());
33        println!("Output: {}", output_dir.display());
34        println!("Settings: {}fps, {}s duration", video_opts.fps, 2);
35
36        converter.convert_video(
37            input,
38            output_dir,
39            &video_opts,
40            &conv_opts,
41            false, // Don't keep intermediate PNG files
42        )?;
43
44        println!("✓ Video conversion complete!");
45        println!("ASCII frames saved to {}", output_dir.display());
46    } else {
47        println!("Note: {} not found.", input.display());
48        println!("To use this example, provide a video file at that path.");
49    }
50
51    Ok(())
52}
More examples
Hide additional examples
examples/simple_image.rs (line 14)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    // Create a converter with default configuration
9    let converter = AsciiConverter::new();
10
11    // Configure conversion options
12    let options = ConversionOptions::default()
13        .with_columns(100)
14        .with_font_ratio(0.5)
15        .with_luminance(20);
16
17    // Example 1: Convert image to ASCII file
18    let input = Path::new("resources/source.png");
19    let output = Path::new("example_output.txt");
20
21    if input.exists() {
22        println!("Converting {} to ASCII art...", input.display());
23        converter.convert_image(input, output, &options)?;
24        println!("✓ ASCII art saved to {}", output.display());
25    } else {
26        println!(
27            "Note: {} not found, skipping file conversion example",
28            input.display()
29        );
30    }
31
32    // Example 2: Convert image to string (no file)
33    if input.exists() {
34        println!("\nConverting image to string...");
35        let ascii_string = converter.image_to_string(input, &options)?;
36        println!(
37            "✓ Generated ASCII string ({} characters)",
38            ascii_string.len()
39        );
40        println!("\nFirst 500 characters:");
41        println!("{}", &ascii_string[..500.min(ascii_string.len())]);
42    }
43
44    // Example 3: Using presets
45    if input.exists() {
46        println!("\n\nUsing 'small' preset...");
47        let small_options = converter.options_from_preset("small")?;
48        let output_small = Path::new("example_output_small.txt");
49        converter.convert_image(input, output_small, &small_options)?;
50        println!("✓ Small ASCII art saved to {}", output_small.display());
51    }
52
53    Ok(())
54}
Source

pub fn with_luminance(self, luminance: u8) -> Self

Create options with a specific luminance threshold

Examples found in repository?
examples/simple_video.rs (line 24)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    // Create a converter
9    let converter = AsciiConverter::new();
10
11    // Configure video options
12    let video_opts = VideoOptions {
13        fps: 10,
14        start: Some("0".to_string()),
15        end: Some("2".to_string()), // Extract first 2 seconds
16        columns: 200,
17        extract_audio: false,
18        preprocess_filter: None,
19    };
20
21    // Configure conversion options
22    let conv_opts = ConversionOptions::default()
23        .with_font_ratio(0.5)
24        .with_luminance(20);
25
26    // Convert video
27    let input = Path::new("tests/video/input/test.mkv");
28    let output_dir = Path::new("example_video_output");
29
30    if input.exists() {
31        println!("Converting video to ASCII frames...");
32        println!("Input: {}", input.display());
33        println!("Output: {}", output_dir.display());
34        println!("Settings: {}fps, {}s duration", video_opts.fps, 2);
35
36        converter.convert_video(
37            input,
38            output_dir,
39            &video_opts,
40            &conv_opts,
41            false, // Don't keep intermediate PNG files
42        )?;
43
44        println!("✓ Video conversion complete!");
45        println!("ASCII frames saved to {}", output_dir.display());
46    } else {
47        println!("Note: {} not found.", input.display());
48        println!("To use this example, provide a video file at that path.");
49    }
50
51    Ok(())
52}
More examples
Hide additional examples
examples/simple_image.rs (line 15)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    // Create a converter with default configuration
9    let converter = AsciiConverter::new();
10
11    // Configure conversion options
12    let options = ConversionOptions::default()
13        .with_columns(100)
14        .with_font_ratio(0.5)
15        .with_luminance(20);
16
17    // Example 1: Convert image to ASCII file
18    let input = Path::new("resources/source.png");
19    let output = Path::new("example_output.txt");
20
21    if input.exists() {
22        println!("Converting {} to ASCII art...", input.display());
23        converter.convert_image(input, output, &options)?;
24        println!("✓ ASCII art saved to {}", output.display());
25    } else {
26        println!(
27            "Note: {} not found, skipping file conversion example",
28            input.display()
29        );
30    }
31
32    // Example 2: Convert image to string (no file)
33    if input.exists() {
34        println!("\nConverting image to string...");
35        let ascii_string = converter.image_to_string(input, &options)?;
36        println!(
37            "✓ Generated ASCII string ({} characters)",
38            ascii_string.len()
39        );
40        println!("\nFirst 500 characters:");
41        println!("{}", &ascii_string[..500.min(ascii_string.len())]);
42    }
43
44    // Example 3: Using presets
45    if input.exists() {
46        println!("\n\nUsing 'small' preset...");
47        let small_options = converter.options_from_preset("small")?;
48        let output_small = Path::new("example_output_small.txt");
49        converter.convert_image(input, output_small, &small_options)?;
50        println!("✓ Small ASCII art saved to {}", output_small.display());
51    }
52
53    Ok(())
54}
Source

pub fn with_ascii_chars(self, ascii_chars: String) -> Self

Create options with custom ASCII character set

Source

pub fn with_output_mode(self, mode: OutputMode) -> Self

Set the output mode

Source

pub fn from_preset(preset: &Preset, ascii_chars: String) -> Self

Create options from a preset

Trait Implementations§

Source§

impl Clone for ConversionOptions

Source§

fn clone(&self) -> ConversionOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ConversionOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ConversionOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.