Compare commits
66 commits
Author | SHA1 | Date | |
---|---|---|---|
|
59ff61bcf1 | ||
|
fd4efce251 | ||
92351bfec8 | |||
|
6110d36adc | ||
|
31c5dac6cb | ||
|
e06ae70b20 | ||
|
69b8f008a9 | ||
|
30d4e3a037 | ||
|
b25849c0bf | ||
|
6d19281100 | ||
|
e4d0da778b | ||
|
1133be9a5a | ||
|
f6dc9a004a | ||
|
8bbc1f7e1d | ||
|
8e403c87bd | ||
c0b2ff6074 | |||
884d8d504c | |||
1ad7f8bf03 | |||
|
9d76b9268d | ||
7d84eaa186 | |||
fe468ffde0 | |||
ec206cb527 | |||
4867f64768 | |||
4d642d07d2 | |||
9001aa5369 | |||
25f2967493 | |||
5a7c5e49fe | |||
997f9261aa | |||
06205bc608 | |||
6baf34bb80 | |||
595f353ff3 | |||
99f73b443e | |||
7699f6c0d9 | |||
d9d1f7c846 | |||
439f5eb880 | |||
74b530c3cf | |||
e58e2dc92c | |||
1e436bfe70 | |||
547997517b | |||
a57ad5a282 | |||
163305c42f | |||
e9793665b4 | |||
dc41987da5 | |||
309449affe | |||
1c79b8a848 | |||
ee50135921 | |||
|
af667544d3 | ||
6814f861eb | |||
0231a5502b | |||
b8f95048e1 | |||
5d89417aa1 | |||
9a7730d2dd | |||
|
e108a1875e | ||
|
0933e157d5 | ||
|
7cc47d7284 | ||
296235de7a | |||
061472ad56 | |||
3dfcb0d273 | |||
|
b4c7738d69 | ||
4d4d246353 | |||
|
1f6a2c7414 | ||
|
706cc5d57d | ||
8e016563e9 | |||
869d6a29d8 | |||
a90b4070f1 | |||
|
f5d6be14b9 |
24
.github/workflows/aur-release.yml
vendored
Normal 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
|
@ -0,0 +1,3 @@
|
|||
[submodule "archpackage/aarty"]
|
||||
path = archpackage/aarty
|
||||
url = ssh://aur@aur.archlinux.org/aarty.git
|
6
.idea/inspectionProfiles/Project_Default.xml
Normal 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>
|
|
@ -2,5 +2,6 @@
|
|||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/archpackage/aarty" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
7
.mergify.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
pull_request_rules:
|
||||
- name: Automatic merge on approval
|
||||
conditions:
|
||||
- "#approved-reviews-by>=1"
|
||||
actions:
|
||||
merge:
|
||||
method: merge
|
10
Cargo.toml
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "aarty"
|
||||
version = "0.1.0"
|
||||
version = "0.4.8"
|
||||
edition = "2021"
|
||||
authors = ["Anas Elgarhy <anas.elgarhy.dev@gmail.com>"]
|
||||
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
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.0.8-rc.3", features = ["derive"] }
|
||||
clap = { version = "4.3.2", features = ["derive"] }
|
||||
colored = "2.0.0"
|
||||
image = "0.24.4"
|
||||
log = "0.4.17"
|
||||
pretty_env_logger = "0.4.0"
|
||||
image = "0.24.6"
|
||||
log = "0.4.18"
|
||||
pretty_env_logger = "0.5.0"
|
||||
|
|
|
@ -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)
|
||||
![money mouth face colored scale 2](./srceenshots/money_mouth_face_colored_scale_2.png)
|
||||
|
@ -56,7 +56,7 @@
|
|||
|
||||
- from crates.io
|
||||
```bash
|
||||
crago install aarty
|
||||
cargo install aarty
|
||||
```
|
||||
- From aur:
|
||||
```shell
|
||||
|
@ -105,6 +105,9 @@ Options:
|
|||
|
||||
[default: 4]
|
||||
|
||||
-w, --width <WIDTH>
|
||||
Enstablish how much wide is the output images, in columns. Overrides `scale`
|
||||
|
||||
-b, --background <BACKGROUND>
|
||||
The background color to use
|
||||
|
||||
|
|
14
archpackage/.SRCINFO
Normal 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
|
@ -0,0 +1,2 @@
|
|||
nas
|
||||
nas
|
41
archpackage/PKGBUILD
Normal 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
|
BIN
images/anime.jpg
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 39 KiB |
BIN
images/image.png
Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 51 KiB |
6
renovate.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"config:base"
|
||||
]
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
pub mod args {
|
||||
use clap::{Parser, arg, ColorChoice};
|
||||
use super::enums::*;
|
||||
use clap::{arg, ColorChoice, Parser};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[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)
|
||||
#[arg(short, long, default_value = "4")]
|
||||
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
|
||||
#[arg(short, long, default_value = None)]
|
||||
pub background: Option<String>,
|
||||
|
@ -29,7 +32,7 @@ pub mod args {
|
|||
|
||||
impl Arguments {
|
||||
pub fn validate(&self) -> Result<(), String> {
|
||||
if self.characters.len() == 0 {
|
||||
if self.characters.is_empty() {
|
||||
return Err("No characters provided".to_string());
|
||||
} else if self.characters.len() == 1 {
|
||||
if self.mode == Mode::NormalAscii {
|
||||
|
@ -53,7 +56,7 @@ pub mod enums {
|
|||
NormalAscii,
|
||||
/// Colored ASCII art, the colors are based on the terminal colors
|
||||
#[clap(alias = "c")]
|
||||
COLORED,
|
||||
Colored,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, ValueEnum, Debug, PartialOrd, Eq, PartialEq)]
|
||||
|
|
|
@ -1,41 +1,51 @@
|
|||
use image::{GenericImageView, DynamicImage};
|
||||
use crate::args::{args::Arguments, enums::Mode};
|
||||
use colored::{ColoredString, Colorize};
|
||||
use crate::args::{
|
||||
args::Arguments,
|
||||
enums::Mode,
|
||||
};
|
||||
use image::{DynamicImage, GenericImageView};
|
||||
|
||||
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>>();
|
||||
trace!("Characters: {:?}, length: {}", characters, characters.len());
|
||||
let mut output = Vec::new();
|
||||
let (width, height) = image.dimensions();
|
||||
let actual_scale = calculate_scale(args, (width, height));
|
||||
|
||||
for y in 0..height {
|
||||
for x in 0..width {
|
||||
if y % (args.scale * 2) == 0 && x % args.scale == 0 {
|
||||
output.push(get_character(
|
||||
if y % (actual_scale * 2) == 0 && x % actual_scale == 0 {
|
||||
let element = get_character(
|
||||
image.get_pixel(x, y),
|
||||
&characters, args.mode,
|
||||
&characters,
|
||||
args.mode,
|
||||
&args.background,
|
||||
));
|
||||
);
|
||||
|
||||
buffer.write_all(format!("{element}").as_bytes())?;
|
||||
}
|
||||
}
|
||||
// Add a new line at the end of each row
|
||||
if y % (args.scale * 2) == 0 {
|
||||
output.push("\n".into());
|
||||
if y % (actual_scale * 2) == 0 {
|
||||
buffer.write_all("\n".as_bytes())?;
|
||||
}
|
||||
}
|
||||
|
||||
output
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_character(
|
||||
pixel: image::Rgba<u8>,
|
||||
characters: &Vec<char>, mode: Mode,
|
||||
characters: &Vec<char>,
|
||||
mode: Mode,
|
||||
background: &Option<String>,
|
||||
) -> 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];
|
||||
|
||||
|
@ -43,14 +53,66 @@ fn get_character(
|
|||
|
||||
let ch = match mode {
|
||||
Mode::NormalAscii => ColoredString::from(&*ch),
|
||||
Mode::COLORED => {
|
||||
ch.to_string()
|
||||
.truecolor(pixel[0], pixel[1], pixel[2])
|
||||
}
|
||||
Mode::Colored => ch.truecolor(pixel[0], pixel[1], pixel[2]),
|
||||
};
|
||||
|
||||
match background {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
42
src/main.rs
|
@ -1,23 +1,22 @@
|
|||
use std::io::Write;
|
||||
use clap::Parser;
|
||||
use image::GenericImageView;
|
||||
|
||||
use std::io::Result;
|
||||
|
||||
extern crate pretty_env_logger;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
mod args;
|
||||
mod ascii_processor;
|
||||
mod output;
|
||||
|
||||
use crate::args::{
|
||||
args::Arguments,
|
||||
enums::OutputMethod,
|
||||
};
|
||||
use crate::args::{args::Arguments, enums::OutputMethod};
|
||||
|
||||
use crate::ascii_processor::generate_ascii;
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<()> {
|
||||
// Initialize the logger
|
||||
pretty_env_logger::init();
|
||||
info!("Successfully initialized logger");
|
||||
|
@ -51,34 +50,7 @@ fn main() {
|
|||
info!("Successfully opened image");
|
||||
trace!("Image dimensions: {:?}", image.dimensions());
|
||||
|
||||
// Process the image
|
||||
let output = generate_ascii(image, &arguments);
|
||||
generate_ascii(image, &arguments, output::prepare_output(&arguments)?)?;
|
||||
info!("Successfully processed image");
|
||||
|
||||
// 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");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
20
src/output.rs
Normal 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))
|
||||
}
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 41 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 7.9 KiB |
Before Width: | Height: | Size: 1.6 MiB After Width: | Height: | Size: 1.5 MiB |
Before Width: | Height: | Size: 3.2 MiB After Width: | Height: | Size: 2.9 MiB |
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 44 KiB |
Before Width: | Height: | Size: 83 KiB After Width: | Height: | Size: 70 KiB |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 7.9 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 47 KiB |
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 92 KiB After Width: | Height: | Size: 84 KiB |
Before Width: | Height: | Size: 104 KiB After Width: | Height: | Size: 96 KiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 8.9 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 22 KiB |