Compare commits

..

66 commits

Author SHA1 Message Date
mergify[bot]
59ff61bcf1
Merge pull request #18 from anas-elgarhy/renovate/clap-4.x
fix(deps): update rust crate clap to 4.3.2
2023-06-08 13:44:08 +00:00
renovate[bot]
fd4efce251
fix(deps): update rust crate clap to 4.3.2 2023-06-05 22:37:29 +00:00
92351bfec8
[deploy] Bump the version 2023-06-03 18:15:55 +03:00
mergify[bot]
6110d36adc
Merge pull request #16 from anas-elgarhy/renovate/log-0.x
fix(deps): update rust crate log to 0.4.18
2023-06-03 15:07:39 +00:00
renovate[bot]
31c5dac6cb
fix(deps): update rust crate log to 0.4.18 2023-06-03 15:06:42 +00:00
mergify[bot]
e06ae70b20
Merge pull request #17 from anas-elgarhy/renovate/pretty_env_logger-0.x
fix(deps): update rust crate pretty_env_logger to 0.5.0
2023-06-03 15:06:28 +00:00
mergify[bot]
69b8f008a9
Merge pull request #15 from anas-elgarhy/renovate/clap-4.x
fix(deps): update rust crate clap to 4.3.1
2023-06-03 15:05:35 +00:00
renovate[bot]
30d4e3a037
fix(deps): update rust crate clap to 4.3.1 2023-06-02 17:41:56 +00:00
renovate[bot]
b25849c0bf
fix(deps): update rust crate pretty_env_logger to 0.5.0 2023-05-28 10:26:03 +00:00
mergify[bot]
6d19281100
Merge pull request #11 from anas-elgarhy/renovate/image-0.x
fix(deps): update rust crate image to 0.24.6
2023-03-31 21:49:21 +00:00
mergify[bot]
e4d0da778b
Merge pull request #12 from anas-elgarhy/renovate/clap-4.x
fix(deps): update rust crate clap to 4.2.1
2023-03-31 21:48:56 +00:00
renovate[bot]
1133be9a5a
fix(deps): update rust crate clap to 4.2.1 2023-03-29 19:27:28 +00:00
renovate[bot]
f6dc9a004a
fix(deps): update rust crate image to 0.24.6 2023-03-25 03:03:19 +00:00
mergify[bot]
8bbc1f7e1d
Merge pull request #14 from anas-elgarhy/renovate/actions-checkout-3.x
chore(deps): update actions/checkout action to v3
2023-01-29 11:35:47 +00:00
renovate[bot]
8e403c87bd
chore(deps): update actions/checkout action to v3 2023-01-28 23:35:09 +00:00
c0b2ff6074
Merge pull request #9 from anas-elgarhy/renovate/configure
Configure Renovate
2023-01-29 01:34:03 +02:00
884d8d504c
Merge pull request #10 from anas-elgarhy/mergify/anas-elgarhy/config-update
ci(Mergify): configuration update
2023-01-29 00:36:54 +02:00
1ad7f8bf03 ci(Mergify): configuration update
Signed-off-by: Anas Elgarhy <anas.elgarhy.dev@gmail.com>
2023-01-29 00:29:33 +02:00
renovate[bot]
9d76b9268d
Add renovate.json 2023-01-28 21:12:54 +00:00
7d84eaa186 Update 2022-11-14 21:28:42 +02:00
fe468ffde0 Update yooo [test workflow only] 2022-11-13 22:20:24 +02:00
ec206cb527 Update yooo [test workflow only] 2022-11-13 19:12:04 +02:00
4867f64768 Update yooo [test workflow only] 2022-11-13 19:02:50 +02:00
4d642d07d2 Update yooo [test workflow only] 2022-11-13 18:48:13 +02:00
9001aa5369 Update yooo [test workflow only] 2022-11-13 16:45:23 +02:00
25f2967493 Update yooo [test workflow only] 2022-11-13 15:43:14 +02:00
5a7c5e49fe Update yooo 2022-11-12 19:10:05 +02:00
997f9261aa Update yoo 2022-11-12 18:26:56 +02:00
06205bc608 Update 2022-11-12 17:30:41 +02:00
6baf34bb80 Update 2022-11-12 14:42:32 +02:00
595f353ff3 Up version 🥲 agein 2022-11-10 01:27:02 +02:00
99f73b443e Up version 🥲 agein 2022-11-10 00:47:31 +02:00
7699f6c0d9 Up version 🥲 agein 2022-11-10 00:02:15 +02:00
d9d1f7c846 Up version 🥲 agein 2022-11-09 21:33:09 +02:00
439f5eb880 Up version 🥲 2022-11-09 21:17:56 +02:00
74b530c3cf Up version 🥲 2022-11-09 20:52:56 +02:00
e58e2dc92c Up version 🥲 2022-11-09 20:31:53 +02:00
1e436bfe70 Up version 🥲 2022-11-09 20:02:15 +02:00
547997517b Up version 🥲 2022-11-09 19:26:33 +02:00
a57ad5a282 Up version 🥲 2022-11-09 19:22:24 +02:00
163305c42f :") 2022-11-09 18:44:52 +02:00
e9793665b4 Bumb :/ 2022-11-09 17:57:45 +02:00
dc41987da5 Fix action version 2022-11-09 17:42:42 +02:00
309449affe Update :) 2022-11-09 17:40:08 +02:00
1c79b8a848 Update 2022-11-09 15:25:46 +02:00
ee50135921 Bumb version agin 2022-11-09 13:37:14 +02:00
Anas Elgarhy
af667544d3
Merge pull request #8 from anas-elgarhy/fix-aur-packge
Fix action configration
2022-11-09 13:37:27 +02:00
6814f861eb Fix action configration 2022-11-09 13:33:57 +02:00
0231a5502b Bumb version -> 0.2.1 2022-11-09 13:27:07 +02:00
b8f95048e1
Merge pull request #7 from anas-elgarhy/add-aur-action
Create the aur-release action yoo ;D
2022-11-09 13:27:49 +02:00
5d89417aa1 Create the aur-release action yoo ;D 2022-11-09 13:17:45 +02:00
9a7730d2dd
Merge pull request #6 from giulio-Joshi/columns_arg
Feature: `width` argument to calculate scale from number of available columns
2022-10-26 21:36:20 +02:00
giulio-Joshi
e108a1875e Fixing requested changes
* Documentation consistency
* Method inlining
2022-10-26 19:52:58 +02:00
giulio-Joshi
0933e157d5 Typo fix 2022-10-25 21:11:53 +02:00
giulio-Joshi
7cc47d7284 Terminal interface: width parameter
Will calculate scaling based on parameter-specified columns number.
2022-10-25 21:07:22 +02:00
296235de7a Update the AUR package 😆 2022-10-11 12:52:23 +02:00
061472ad56 Update the dependencies and up the version 💙 2022-10-11 12:45:47 +02:00
3dfcb0d273
Merge pull request #5 from giulio-Joshi/bufferedOutput
Modular output methods
2022-10-10 23:59:52 +02:00
giulio-Joshi
b4c7738d69 Modular output methods
Using a `std::io::BufWriter` to wrap the output should allow more flexibility.
2022-10-10 22:17:21 +02:00
4d4d246353
Merge pull request #3 from Ashish-Abraham/master
Fixed typo error in installation instruction
2022-10-09 12:15:44 +02:00
Ashish Abraham
1f6a2c7414
Update README.md 2022-10-09 15:36:04 +05:30
Ashish Abraham
706cc5d57d
Fixed error in installation instruction
Corrected typo error in installation from crates.io
2022-10-09 15:33:38 +05:30
8e016563e9 Fix aur package 😆 2022-10-04 12:41:48 +02:00
869d6a29d8
Merge pull request #1 from anas-elgarhy/imgbot
[ImgBot] Optimize images
2022-10-03 23:44:55 +02:00
a90b4070f1 Create The AUR package 😆 2022-10-03 23:41:59 +02:00
ImgBotApp
f5d6be14b9
[ImgBot] Optimize images
*Total -- 5,869.14kb -> 5,195.53kb (11.48%)

/srceenshots/heart_normal_scale_2.png -- 14.98kb -> 3.59kb (76.05%)
/srceenshots/airplane_normal_scale_2.png -- 32.85kb -> 7.93kb (75.86%)
/srceenshots/penguin_normal_scale_2.png -- 35.39kb -> 8.90kb (74.85%)
/srceenshots/money_mouth_face_normal_scale_2.png -- 42.65kb -> 10.94kb (74.34%)
/srceenshots/nerd_face_normal_scale_2.png -- 34.72kb -> 10.08kb (70.97%)
/srceenshots/crap_normal_scale_2.png -- 26.30kb -> 7.91kb (69.92%)
/srceenshots/penguin_colored_scale_2.png -- 36.38kb -> 28.46kb (21.75%)
/srceenshots/nerd_face_colored_scale_2.png -- 39.83kb -> 32.47kb (18.47%)
/srceenshots/airplane_colored_scale_2.png -- 49.23kb -> 40.60kb (17.53%)
/srceenshots/crap_colored_scale_2.png -- 34.35kb -> 28.65kb (16.6%)
/srceenshots/money_mouth_face_colored_scale_2.png -- 56.34kb -> 47.11kb (16.39%)
/srceenshots/red_heart_colored_scale_2.png -- 26.32kb -> 22.17kb (15.79%)
/srceenshots/airplane_colored_scale_4.png -- 17.50kb -> 14.75kb (15.72%)
/srceenshots/crap_colored_scale_1.png -- 82.96kb -> 70.20kb (15.38%)
/images/image.png -- 59.54kb -> 50.70kb (14.85%)
/srceenshots/blue_heart_colored_scale_2.png -- 49.70kb -> 44.00kb (11.46%)
/srceenshots/anime_colored_scale_3.gif -- 3,318.20kb -> 3,018.90kb (9.02%)
/srceenshots/ok_hand_colored_scale_4_custome_chars.png -- 91.92kb -> 83.66kb (8.99%)
/srceenshots/anime_2_colored_scale_4.gif -- 1,646.40kb -> 1,501.38kb (8.81%)
/srceenshots/ok_hand_colored_scale_4_custome_chars_in_file.png -- 104.54kb -> 95.61kb (8.54%)
/images/anime_2.jpg -- 40.88kb -> 39.42kb (3.57%)
/images/anime.jpg -- 28.17kb -> 28.09kb (0.27%)

Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>
2022-10-03 21:39:49 +00:00
38 changed files with 232 additions and 67 deletions

24
.github/workflows/aur-release.yml vendored Normal file
View file

@ -0,0 +1,24 @@
name: aur-release
on:
push:
tags:
- "*" # Run on any tag
jobs:
aur-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Publish AUR package
uses: anas-elgarhy/aur-release-action@v4.1
with:
ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
pkgbuild_path: archpackage/PKGBUILD # Use this if the PKGBUILD file is not in the root directory
# aur_submodule_path: archpackage/aarty
git_username: Anas Elgarhy # Use this if you want to change the git username (recommended)
git_email: anas.elgarhy.dev@gmail.com # Use this if you want to change the git email (recommended)
commit_message: UpUp Update %FILENAME% to %VERSION% yoo # Use this if you want to change the commit message
try_build_and_install: false

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "archpackage/aarty"]
path = archpackage/aarty
url = ssh://aur@aur.archlinux.org/aarty.git

View file

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="AndroidLintDuplicateStrings" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>

View file

@ -2,5 +2,6 @@
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" /> <mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/archpackage/aarty" vcs="Git" />
</component> </component>
</project> </project>

7
.mergify.yml Normal file
View file

@ -0,0 +1,7 @@
pull_request_rules:
- name: Automatic merge on approval
conditions:
- "#approved-reviews-by>=1"
actions:
merge:
method: merge

View file

@ -1,6 +1,6 @@
[package] [package]
name = "aarty" name = "aarty"
version = "0.1.0" version = "0.4.8"
edition = "2021" edition = "2021"
authors = ["Anas Elgarhy <anas.elgarhy.dev@gmail.com>"] authors = ["Anas Elgarhy <anas.elgarhy.dev@gmail.com>"]
description = "A simple CLI tool to convert the images to ASCII art" description = "A simple CLI tool to convert the images to ASCII art"
@ -31,8 +31,8 @@ exclude = ["images/*"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
clap = { version = "4.0.8-rc.3", features = ["derive"] } clap = { version = "4.3.2", features = ["derive"] }
colored = "2.0.0" colored = "2.0.0"
image = "0.24.4" image = "0.24.6"
log = "0.4.17" log = "0.4.18"
pretty_env_logger = "0.4.0" pretty_env_logger = "0.5.0"

View file

@ -1,4 +1,4 @@
# aarty: A simple CLI tool to convert the images to ASCII art with rust 🦀 # aarty: A simple CLI tool to convert images to ASCII art with Rust 🦀
![srceenshots/anime_2_colored_scale_4.gif](./srceenshots/anime_2_colored_scale_4.gif) ![srceenshots/anime_2_colored_scale_4.gif](./srceenshots/anime_2_colored_scale_4.gif)
![money mouth face colored scale 2](./srceenshots/money_mouth_face_colored_scale_2.png) ![money mouth face colored scale 2](./srceenshots/money_mouth_face_colored_scale_2.png)
@ -56,7 +56,7 @@
- from crates.io - from crates.io
```bash ```bash
crago install aarty cargo install aarty
``` ```
- From aur: - From aur:
```shell ```shell
@ -105,6 +105,9 @@ Options:
[default: 4] [default: 4]
-w, --width <WIDTH>
Enstablish how much wide is the output images, in columns. Overrides `scale`
-b, --background <BACKGROUND> -b, --background <BACKGROUND>
The background color to use The background color to use

14
archpackage/.SRCINFO Normal file
View file

@ -0,0 +1,14 @@
pkgbase = aarty
pkgdesc = A simple CLI tool to convert the images to ASCII art 🦀💙
pkgver = 0.2.0
pkgrel = 1
url = https://github.com/anas-elgarhy/aarty
arch = x86_64
license = MIT
makedepends = cargo
provides = aarty
replaces = aarty
source = aarty-0.2.0.tar.gz::https://static.crates.io/crates/aarty/aarty-0.2.0.crate
sha256sums = aa8cdf26ac78adf035088d6e12730a593e17a040f54ebfe39f59fc9c438be1c4
pkgname = aarty

2
archpackage/A Normal file
View file

@ -0,0 +1,2 @@
nas
nas

41
archpackage/PKGBUILD Normal file
View file

@ -0,0 +1,41 @@
# Maintainer: Anas Elgarhy <anas.elgarhy.dev@gmail.com>
pkgname=aarty
pkgver=0.2.0
pkgrel=1
epoch=
pkgdesc="A simple CLI tool to convert the images to ASCII art 🦀💙"
arch=(x86_64)
url="https://github.com/anas-elgarhy/aarty"
license=('MIT')
makedepends=(cargo)
provides=(aarty)
conflicts=()
replaces=(aarty)
install=
changelog=
source=("$pkgname-$pkgver.tar.gz::https://static.crates.io/crates/$pkgname/$pkgname-$pkgver.crate")
noextract=()
prepare() {
cd "$pkgname-$pkgver"
cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}
build() {
cd "$pkgname-$pkgver"
export RUSTUP_TOOLCHAIN=stable
export CARGO_TARGET_DIR=target
cargo build --frozen --release --all-features
}
check() {
cd "$pkgname-$pkgver"
export RUSTUP_TOOLCHAIN=stable
cargo test --frozen --all-features
}
package() {
cd "$pkgname-$pkgver"
sudo install -Dm0755 -t "/usr/bin/" "target/release/$pkgname"
}
sha256sums=('aa8cdf26ac78adf035088d6e12730a593e17a040f54ebfe39f59fc9c438be1c4')

1
archpackage/aarty Submodule

@ -0,0 +1 @@
Subproject commit b32218c382efd1a956f5f9fcc151aec90862d6e5

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

After

Width:  |  Height:  |  Size: 51 KiB

6
renovate.json Normal file
View file

@ -0,0 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
]
}

View file

@ -1,6 +1,6 @@
pub mod args { pub mod args {
use clap::{Parser, arg, ColorChoice};
use super::enums::*; use super::enums::*;
use clap::{arg, ColorChoice, Parser};
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(author, version, about, long_about = None, color = ColorChoice::Always)] #[command(author, version, about, long_about = None, color = ColorChoice::Always)]
@ -19,6 +19,9 @@ pub mod args {
/// The output scale (1 is the original size) /// The output scale (1 is the original size)
#[arg(short, long, default_value = "4")] #[arg(short, long, default_value = "4")]
pub scale: u32, pub scale: u32,
/// Enstablish how much wide is the output images, in columns. Overrides `scale`
#[arg(short, long, default_value= None )]
pub width: Option<u32>,
/// The background color to use /// The background color to use
#[arg(short, long, default_value = None)] #[arg(short, long, default_value = None)]
pub background: Option<String>, pub background: Option<String>,
@ -29,7 +32,7 @@ pub mod args {
impl Arguments { impl Arguments {
pub fn validate(&self) -> Result<(), String> { pub fn validate(&self) -> Result<(), String> {
if self.characters.len() == 0 { if self.characters.is_empty() {
return Err("No characters provided".to_string()); return Err("No characters provided".to_string());
} else if self.characters.len() == 1 { } else if self.characters.len() == 1 {
if self.mode == Mode::NormalAscii { if self.mode == Mode::NormalAscii {
@ -53,7 +56,7 @@ pub mod enums {
NormalAscii, NormalAscii,
/// Colored ASCII art, the colors are based on the terminal colors /// Colored ASCII art, the colors are based on the terminal colors
#[clap(alias = "c")] #[clap(alias = "c")]
COLORED, Colored,
} }
#[derive(Copy, Clone, ValueEnum, Debug, PartialOrd, Eq, PartialEq)] #[derive(Copy, Clone, ValueEnum, Debug, PartialOrd, Eq, PartialEq)]

View file

@ -1,41 +1,51 @@
use image::{GenericImageView, DynamicImage}; use crate::args::{args::Arguments, enums::Mode};
use colored::{ColoredString, Colorize}; use colored::{ColoredString, Colorize};
use crate::args::{ use image::{DynamicImage, GenericImageView};
args::Arguments,
enums::Mode,
};
pub fn generate_ascii(image: DynamicImage, args: &Arguments) -> Vec<ColoredString> { use std::io::{self, BufWriter, Write};
pub fn generate_ascii<W: Write>(
image: DynamicImage,
args: &Arguments,
mut buffer: BufWriter<W>,
) -> io::Result<()> {
let characters = args.characters.chars().collect::<Vec<char>>(); let characters = args.characters.chars().collect::<Vec<char>>();
trace!("Characters: {:?}, length: {}", characters, characters.len());
let mut output = Vec::new();
let (width, height) = image.dimensions(); let (width, height) = image.dimensions();
let actual_scale = calculate_scale(args, (width, height));
for y in 0..height { for y in 0..height {
for x in 0..width { for x in 0..width {
if y % (args.scale * 2) == 0 && x % args.scale == 0 { if y % (actual_scale * 2) == 0 && x % actual_scale == 0 {
output.push(get_character( let element = get_character(
image.get_pixel(x, y), image.get_pixel(x, y),
&characters, args.mode, &characters,
args.mode,
&args.background, &args.background,
)); );
buffer.write_all(format!("{element}").as_bytes())?;
} }
} }
// Add a new line at the end of each row // Add a new line at the end of each row
if y % (args.scale * 2) == 0 { if y % (actual_scale * 2) == 0 {
output.push("\n".into()); buffer.write_all("\n".as_bytes())?;
} }
} }
output Ok(())
} }
fn get_character( fn get_character(
pixel: image::Rgba<u8>, pixel: image::Rgba<u8>,
characters: &Vec<char>, mode: Mode, characters: &Vec<char>,
mode: Mode,
background: &Option<String>, background: &Option<String>,
) -> ColoredString { ) -> ColoredString {
let intent = if pixel[3] == 0 { 0 } else { pixel[0] / 3 + pixel[1] / 3 + pixel[2] / 3 }; let intent = if pixel[3] == 0 {
0
} else {
pixel[0] / 3 + pixel[1] / 3 + pixel[2] / 3
};
let ch = characters[(intent / (32 + 7 - (7 + (characters.len() - 7)) as u8)) as usize]; let ch = characters[(intent / (32 + 7 - (7 + (characters.len() - 7)) as u8)) as usize];
@ -43,14 +53,66 @@ fn get_character(
let ch = match mode { let ch = match mode {
Mode::NormalAscii => ColoredString::from(&*ch), Mode::NormalAscii => ColoredString::from(&*ch),
Mode::COLORED => { Mode::Colored => ch.truecolor(pixel[0], pixel[1], pixel[2]),
ch.to_string()
.truecolor(pixel[0], pixel[1], pixel[2])
}
}; };
match background { match background {
Some(bg) => ch.on_color(bg.to_string()), Some(bg) => ch.on_color(bg.to_string()),
None => ch None => ch,
}
}
///
/// Determine how much scale to use in presence of `width` parameters,
/// otherwise returns regular `scale` parameter per default behaviour
///
#[inline]
fn calculate_scale(args: &Arguments, dimensions: (u32, u32)) -> u32 {
args.width.map_or_else(|| args.scale, |v| dimensions.0 / v)
}
#[cfg(test)]
mod test {
use crate::args::{
args::Arguments,
enums::{Mode, OutputMethod},
};
use super::calculate_scale;
const DIMENSIONS: (u32, u32) = (100, 100);
#[test]
fn test_scale() {
let args = Arguments {
mode: Mode::NormalAscii,
output_method: OutputMethod::Stdout,
image: "".into(),
characters: "".into(),
scale: 4,
width: Some(10),
background: None,
output: "".into(),
};
let scale = calculate_scale(&args, DIMENSIONS);
assert_eq!(scale, 10);
}
#[test]
fn test_default_scale() {
let args = Arguments {
mode: Mode::NormalAscii,
output_method: OutputMethod::Stdout,
image: "".into(),
characters: "".into(),
scale: 4,
width: None,
background: None,
output: "".into(),
};
let scale = calculate_scale(&args, DIMENSIONS);
assert_eq!(scale, 4);
} }
} }

View file

@ -1,23 +1,22 @@
use std::io::Write;
use clap::Parser; use clap::Parser;
use image::GenericImageView; use image::GenericImageView;
use std::io::Result;
extern crate pretty_env_logger; extern crate pretty_env_logger;
#[macro_use] #[macro_use]
extern crate log; extern crate log;
mod args; mod args;
mod ascii_processor; mod ascii_processor;
mod output;
use crate::args::{ use crate::args::{args::Arguments, enums::OutputMethod};
args::Arguments,
enums::OutputMethod,
};
use crate::ascii_processor::generate_ascii; use crate::ascii_processor::generate_ascii;
fn main() { fn main() -> Result<()> {
// Initialize the logger // Initialize the logger
pretty_env_logger::init(); pretty_env_logger::init();
info!("Successfully initialized logger"); info!("Successfully initialized logger");
@ -51,34 +50,7 @@ fn main() {
info!("Successfully opened image"); info!("Successfully opened image");
trace!("Image dimensions: {:?}", image.dimensions()); trace!("Image dimensions: {:?}", image.dimensions());
// Process the image generate_ascii(image, &arguments, output::prepare_output(&arguments)?)?;
let output = generate_ascii(image, &arguments);
info!("Successfully processed image"); info!("Successfully processed image");
Ok(())
// Output the image
info!("Outputting image");
match arguments.output_method {
OutputMethod::File => {
match std::fs::write(
arguments.output.clone(),
output.iter()
.map(|s| format!("{}", s))
.collect::<String>(),
) {
Ok(_) => info!("Successfully outputted image: {}", arguments.output),
Err(e) => {
error!("Failed to output image: {:?}", e);
eprintln!("Failed to output image: {:?}", e);
std::process::exit(1);
}
}
}
OutputMethod::Stdout => {
for char in output {
print!("{}", char);
std::io::stdout().flush().unwrap();
}
info!("Successfully outputted image");
}
}
} }

20
src/output.rs Normal file
View file

@ -0,0 +1,20 @@
use std::fs::File;
use std::io;
use std::io::BufWriter;
use std::io::Write;
use super::Arguments;
use super::OutputMethod;
pub fn prepare_output(arguments: &Arguments) -> io::Result<BufWriter<Box<dyn Write>>> {
match arguments.output_method {
OutputMethod::File => {
let output_file = Box::new(File::create(&arguments.output)?);
Ok(BufWriter::with_capacity(1024, output_file))
}
OutputMethod::Stdout => {
let output_wrap = Box::new(std::io::stdout().lock());
Ok(BufWriter::with_capacity(1024, output_wrap))
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 MiB

After

Width:  |  Height:  |  Size: 2.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 83 KiB

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 104 KiB

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 22 KiB