For those purely interested in the algorithm part of the repo, this seems to be it:
```
/// Implementation for converting an image to ASCII art.
impl ToAsciiArt for ImageConverter {
fn to_ascii_art(&self, options: Option<AsciiOptions>) -> String {
let options = options.unwrap_or_default();
let target_width = options.width;
let target_height = options.height;
let width_ratio = self.image.width() as f32 / target_width as f32;
let height_ratio = self.image.height() as f32 / target_height as f32;
let mut ascii_art = String::with_capacity((target_width * target_height) as usize);
for y in 0..target_height {
for x in 0..target_width {
let start_x = (x as f32 * width_ratio) as u32;
let start_y = (y as f32 * height_ratio) as u32;
let mut total_r = 0;
let mut total_g = 0;
let mut total_b = 0;
for dy in 0..height_ratio as u32 {
for dx in 0..width_ratio as u32 {
let pixel = self.image.get_pixel(start_x + dx, start_y + dy);
let channels = pixel.channels();
total_r += channels[0] as u32;
total_g += channels[1] as u32;
total_b += channels[2] as u32;
}
}
let count = (width_ratio * height_ratio) as u32;
let avg_r = (total_r / count) as u8;
let avg_g = (total_g / count) as u8;
let avg_b = (total_b / count) as u8;
let luminance = (0.2126 * avg_r as f32 + 0.7152 * avg_g as f32 + 0.0722 * avg_b as f32) as u8;
let character = match luminance {
0..=31 => '#',
32..=63 => '@',
64..=95 => '8',
96..=127 => '&',
128..=159 => 'o',
160..=191 => ':',
192..=223 => '*',
224..=255 => '.',
};
ascii_art.push(character);
}
ascii_art.push('\n');
}
ascii_art
}
While this is cool, I am long entertained by memories of playing music videos through cacalib with mplayer which generates color ascii art video (over SSH no less :)
(This. Is snowI have twice now written fairly involved comments telling you about and linking to a tool I made that runs in the browser (completely locally) and outputs to HTML and CSS (which in my case is technically using the ASCII character set so I think we’re in the same ballpark) a full-color text representation of the image you choose.
Twice now I have inadvertently navigated off of the comment page while trying to live text to a part of my phone’s screen that isn’t smashed and can actually display. So this is the third attempt to share this with you, let’s hope it elevates is the charm.
The page I am about to link to explains and demonstrates what IMHO looks much better than the output of similar tools, even when running the plain old black text on white background version of the tool. Though the demo picture
Since you are reading this article and at least some of the comments, I hope you will check it out and enjoy using it. The somewhat arbitrarily chosen
The linked tool is great, it creates some incredibly nice-looking art! Is it open-sourced? I'd be curious to see how the HTML / CSS approach is implemented.
Truth be told, cranking the width and height up on my tool spits out a pretty accurate-looking result too, though granted without offsetting individual characters you can only go so far haha! Scaling the width and height down averages out the image to create a less detailed approximation.
Thank you! I had fun with it and wills I said, was really surprised and happy that my coloring “algorithm” works as well as it does. I spent a lot more time trying to figure out how to make the upload, convert to bitmap array, draw on canvas stuff work (and the trial and error is probably pretty obvious as all the commented code and lack of formatting lays evident. It was a “finally, it works… go to bed” situation. )
Yes, it’s open source I. The sense that it runs entirely in your browser.
:-) i don’t think I put any license in the code but I do t remember for sure.). That’s the web though right? If you like it, view it Learn it use it, right?
I haven’t put it in my GitHub because it’s really heinous code with lots of commented out nonsense as I was trying to figure out the html canvas, css, and JavaScript to make it work. (None of those pay my bills so it was as much a curiosity for me as it is to you. )
But yeah, if you promise not to point and laugh at how sloppy it is, just “view source”, or Ctrl-shift/I, or right-click|Inspect.. whatever your preferred method is. I may clean it up and make it more accessible if it seems of interest to folks.
Thanks again for taking a look and making time to comment on my tool, especially as a minor threadjack my comment was. :-)
We certainly could do something like that, but I thought a simple html form - which can be run by loading the file locally just as well as connecting to my webserver; once you download the html file (which contains the javascriot to manipulate the canvas and other dom stuff) - it runs completely locally. Using the browser as the UI makes it “native” to any os/hardware architecture that can run Firefox, Chrome, Safari, Opera, Brave, etc. I was thinking a simple html file that can be run anywhere would be a preferred platform, though I acknowledge a more popular diversion from natively compiled apps is containerized apps, but really there must be some sensible line we acknowledge where going packaged or containerized is overkill, no? (Probably no. AndI probably shouldn’t speak such heresy if I like earning a paycheck. . ;-)
I hope my rambling doesn’t come across as an assholish response; I’m just kinda thinking aloud.
I might be a bit biased here, but I don't consider that native, nor any of the electron-like wrappers around such creations. The only true native app e.g. for windows is an EXE, compiled from any of the languages that are capable of producing x86 binaries.