Compare commits

..

No commits in common. "master" and "0.1.0" have entirely different histories.

38 changed files with 67 additions and 232 deletions

View file

@ -1,24 +0,0 @@
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
View file

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

View file

@ -1,6 +0,0 @@
<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,6 +2,5 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/archpackage/aarty" vcs="Git" />
</component>
</project>

View file

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

View file

@ -1,6 +1,6 @@
[package]
name = "aarty"
version = "0.4.8"
version = "0.1.0"
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.3.2", features = ["derive"] }
clap = { version = "4.0.8-rc.3", features = ["derive"] }
colored = "2.0.0"
image = "0.24.6"
log = "0.4.18"
pretty_env_logger = "0.5.0"
image = "0.24.4"
log = "0.4.17"
pretty_env_logger = "0.4.0"

View file

@ -1,4 +1,4 @@
# aarty: A simple CLI tool to convert images to ASCII art with Rust 🦀
# aarty: A simple CLI tool to convert the 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
cargo install aarty
crago install aarty
```
- From aur:
```shell
@ -105,9 +105,6 @@ 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

View file

@ -1,14 +0,0 @@
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

View file

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

View file

@ -1,41 +0,0 @@
# 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 +0,0 @@
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: 39 KiB

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 60 KiB

View file

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

View file

@ -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,9 +19,6 @@ 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>,
@ -32,7 +29,7 @@ pub mod args {
impl Arguments {
pub fn validate(&self) -> Result<(), String> {
if self.characters.is_empty() {
if self.characters.len() == 0 {
return Err("No characters provided".to_string());
} else if self.characters.len() == 1 {
if self.mode == Mode::NormalAscii {
@ -56,7 +53,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)]

View file

@ -1,51 +1,41 @@
use crate::args::{args::Arguments, enums::Mode};
use image::{GenericImageView, DynamicImage};
use colored::{ColoredString, Colorize};
use image::{DynamicImage, GenericImageView};
use crate::args::{
args::Arguments,
enums::Mode,
};
use std::io::{self, BufWriter, Write};
pub fn generate_ascii<W: Write>(
image: DynamicImage,
args: &Arguments,
mut buffer: BufWriter<W>,
) -> io::Result<()> {
pub fn generate_ascii(image: DynamicImage, args: &Arguments) -> Vec<ColoredString> {
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 % (actual_scale * 2) == 0 && x % actual_scale == 0 {
let element = get_character(
if y % (args.scale * 2) == 0 && x % args.scale == 0 {
output.push(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 % (actual_scale * 2) == 0 {
buffer.write_all("\n".as_bytes())?;
if y % (args.scale * 2) == 0 {
output.push("\n".into());
}
}
Ok(())
output
}
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];
@ -53,66 +43,14 @@ fn get_character(
let ch = match mode {
Mode::NormalAscii => ColoredString::from(&*ch),
Mode::Colored => ch.truecolor(pixel[0], pixel[1], pixel[2]),
Mode::COLORED => {
ch.to_string()
.truecolor(pixel[0], pixel[1], pixel[2])
}
};
match background {
Some(bg) => ch.on_color(bg.to_string()),
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);
None => ch
}
}

View file

@ -1,22 +1,23 @@
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() -> Result<()> {
fn main() {
// Initialize the logger
pretty_env_logger::init();
info!("Successfully initialized logger");
@ -50,7 +51,34 @@ fn main() -> Result<()> {
info!("Successfully opened image");
trace!("Image dimensions: {:?}", image.dimensions());
generate_ascii(image, &arguments, output::prepare_output(&arguments)?)?;
// Process the image
let output = generate_ascii(image, &arguments);
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");
}
}
}

View file

@ -1,20 +0,0 @@
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: 41 KiB

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 MiB

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 MiB

After

Width:  |  Height:  |  Size: 3.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 KiB

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.9 KiB

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 26 KiB