5 ms·
ASCII-Gen, a CLI tool that converts images to ASCII art
- iampims 3y agoI’d recommend adding an example of the output to the repo’s README. Let us see what this tool can do without having to install it.
- thed24 3y agoDone! Can't believe this slipped my mind haha EDIT: Have added an example of both a shrunken output, and a detailed zoomed out output.
- whym 3y agoIt looks like this is what it does essentially: 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 => '.', }; https://github.com/thed24/ascii-gen/blob/main/src/converter.rs https://github.com/thed24/ascii-gen/blob/main/src/converter....
- PrimeMcFly 3y agoWhat does 'luminance' mean in this context?
- qbrass 3y agoIt's scaling the colors differently to account for perceived brightness differences instead of just averaging RGB values.
- PrimeMcFly 3y agoAh, thank you!
- lathiat 3y agoWhile 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 :)
- eran- 3y agoansi art <3
- JTyQZSnP3cQGa8B 3y agoWe used to watch movies for fun like this 20 years ago over SSH. It was stupid but technically interesting because we were discovering the internet. As for OP, he should try one of the libcaca wrapper for Rust, or make one as an exercise.
- politelemon 3y agoI will be trying this out! Are there other tools like this?
- Instantnoodl 3y agoIf you use a more modern terminal you can also use stuff like: https://hpjansson.org/chafa/ https://hpjansson.org/chafa/ https://github.com/BigJk/imeji https://github.com/BigJk/imeji
- xrd 3y agoYou can watch entire videos using gstreamer and aasink. gst-launch-1.0 filesrc location=my video.webm ! videoconvert ! aasink This is a great way to watch videos inside your terminal. Or, a terrible way to watch videos, I suppose, it depends on how much you like ASCII art.
- lcall 3y agoI remember VLC (the video player) having an output option for playing a video as ascii art. I could actually recognize some of the items in the scene.
- dholm 3y agohttps://aa-project.sourceforge.net/aalib/ https://aa-project.sourceforge.net/aalib/
- ycombiredd 3y ago(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 https://www.killsignal.net/img2txt/ascii-art.html https://www.killsignal.net/img2txt/ascii-art.html
- integricho 3y agomake a native app / tool from it please.
- ycombiredd 3y agoWe 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.
- 3y ago
- extasia 3y agoFor 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 } } ```
- ZeroGravitas 3y agoBeing able to tweak the levels/gamma,channels live and see the output feels like it would be useful here for dialling in the best output.
- thed24 3y agoThis is a really good idea, let me see what I can do. Might be worth pulling in a TUI lib. Thanks for the feedback :)
- deleted 3y ago[deleted]