Skip to content

Commit

Permalink
docs(readme): re-generate the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
0x61nas committed Jan 28, 2024
1 parent 82bf36f commit 6d872d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ mini freamwork to render images in the terminals/ttys.

## Examples
```rust
let cfg = Config {
sympols: vec![' ', '.', ',', '-', '~', '!', '*', '%', '$', '@', '#'].into(),
background: None,
flags: 0,
};
let cfg = Config::new(vec![' ', '.', ',', '-', '~', '!', '*', '%', '$', '@', '#'].into());

let image = image::open("mylove.jpg").unwrap();
let (w, h) = image.dimensions();

Expand All @@ -24,22 +21,18 @@ convert_image_to_ascii(&cfg, &image, &mut out).expect("IO error");
```
Enable the foreground colors
```rust
let cfg = Config {
sympols: vec![' ', '.', ',', '-', '~', '!', '*', '%', '$', '@', '#'].into(),
background: None,
flags: COLORS,
};
let cfg = Config::new(vec![' ', '.', ',', '-', '~', '!', '*', '%'].into()).with_flags(COLORS);

// ...
```

Reverse them with the background color
```rust
let cfg = Config {
sympols: Sympols::empty(),
background: Some((232, 209, 204).into()),
flags: COLORS | REVERSE,
};
let cfg = Config::new(Sympols::empty()).with_background((232, 209, 204)).with_flags(COLORS | REVERSE);

// ...
```

If you wanna build a rebresentesion in memory so you can modify it or use it multiple times, then you may found that implement [`FragmentWriter`]
for such a structher is useful.
```rust
Expand Down Expand Up @@ -76,11 +69,8 @@ impl FragmentWriter for TerminalFrame {
}

// So you can use it as a buffer
let cfg = Config {
sympols: vec!['.', ',', '0', '1', '2', '3', '4', '5', '6', '8'].into(),
background: None,
flags: 0,
};
let cfg = Config::new(vec!['I', 'L', 'O', 'V', 'E', 'U'].into()).with_flags(COLORS);

let image = image::open("mylove.jpg").unwrap();
let (w, h) = image.dimensions();
let mut frame = TerminalFrame {
Expand All @@ -90,19 +80,17 @@ let mut frame = TerminalFrame {
aarty::convert_image_to_ascii(&cfg, &image, &mut frame).expect("Write error");
// Do whatever you want with this object...
```
But be aware if you take this way, you'll have to implement the rendaring mechanism when its its the time to print the image (a.k.a. rendering it).

But be aware by doing this, you'll have to implement the rendaring mechanism when its its the time to print the image (a.k.a. rendering it).

For such this case, we have [`TextImage`], which basically dose the same thing as the code above but in more ergnomic way, And it does implement the rendering mechanism, so you can just print it, and it will render the image properly.
You can enable this type with `text_image` feature, which is enabled by default.

The `text_image` feature also include the [`ToTextImage`] trait, which provide an ergonomic way to construct an [`TextImage`] object.
```rust
use aarty::ToTextImage;
let cfg = Config {
sympols: Sympols::empty(),
background: Some((232, 209, 204).into()),
flags: COLORS | REVERSE,
};
let cfg = Config::new_with_background(Sympols::empty(), (232, 209, 204).into()).with_flags(COLORS | REVERSE);

let image = image::open("mylove.jpg").unwrap().to_text(cfg);
println!("{image}");
```
Expand Down
Binary file modified _deps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6d872d6

Please sign in to comment.