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: f32Font aspect ratio (width/height of character)
luminance: u8Luminance threshold (0-255) for transparency
ascii_chars: StringASCII character set to use (from darkest to lightest)
output_mode: OutputModeWhat output files to generate
Implementations§
Source§impl ConversionOptions
impl ConversionOptions
Sourcepub fn with_columns(self, columns: u32) -> Self
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}Sourcepub fn with_font_ratio(self, font_ratio: f32) -> Self
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
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}Sourcepub fn with_luminance(self, luminance: u8) -> Self
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
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}Sourcepub fn with_ascii_chars(self, ascii_chars: String) -> Self
pub fn with_ascii_chars(self, ascii_chars: String) -> Self
Create options with custom ASCII character set
Sourcepub fn with_output_mode(self, mode: OutputMode) -> Self
pub fn with_output_mode(self, mode: OutputMode) -> Self
Set the output mode
Sourcepub fn from_preset(preset: &Preset, ascii_chars: String) -> Self
pub fn from_preset(preset: &Preset, ascii_chars: String) -> Self
Create options from a preset
Trait Implementations§
Source§impl Clone for ConversionOptions
impl Clone for ConversionOptions
Source§fn clone(&self) -> ConversionOptions
fn clone(&self) -> ConversionOptions
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ConversionOptions
impl Debug for ConversionOptions
Auto Trait Implementations§
impl Freeze for ConversionOptions
impl RefUnwindSafe for ConversionOptions
impl Send for ConversionOptions
impl Sync for ConversionOptions
impl Unpin for ConversionOptions
impl UnsafeUnpin for ConversionOptions
impl UnwindSafe for ConversionOptions
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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