# ascii-art **Repository Path**: tntxia/ascii-art ## Basic Information - **Project Name**: ascii-art - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-10-30 - **Last Updated**: 2024-10-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README _ _ _ (_)(_) | | __ _ ___ ___ _ _ ______ __ _ _ __ | |_ / _` |/ __| / __|| || ||______| / _` || '__|| __| | (_| |\__ \| (__ | || | | (_| || | | |_ \__,_||___/ \___||_||_| \__,_||_| \__| ascii-art.js ============ []() []() []() [](https://github.com/khrome/ascii-art) Images, fonts, tables, ansi styles and compositing in Node.js & the browser. 100% JS. ([What is ASCII-Art?](https://github.com/khrome/ascii-art-docs/blob/master/History.md)) In the beginning there was [colors.js](https://github.com/Marak/colors.js) but in the fine tradition of vendors calling out a problem they have the solution to, [chalk](https://github.com/yeoman/yo/issues/68) was introduced. In that same vein, I offer `ascii-art` as an update, expansion and generalization of [MooAsciiArt](http://mootools.net/forge/p/mooasciiart) and at the same time it can replace your existing ansi colors library. It features support for [Images](https://www.npmjs.com/package/ascii-art-image), [Styles](https://github.com/khrome/ascii-art-docs/blob/master/Styles.md), [Tables](https://www.npmjs.com/package/ascii-art-table), [Graphs](https://www.npmjs.com/package/ascii-art-graph) and [Figlet Fonts](https://www.npmjs.com/package/ascii-art-font) as well as handling multi-line joining and compositing automatically.
- **modular** - small set of purpose built modules all interacting through a common ansi library.
- **color profiles** support - other libraries mostly assume you are running x11.
- **no prototype manipulation** - No `String.prototype` usage. No `__proto__` usage. No BS.
- handles the ugly [intersection of **multiline text and ansi codes**](https://github.com/khrome/ascii-art-docs/blob/master/Multiline.md) for you.
- runs in the **browser and Node.js** (CommonJS, AMD, globals, webpack, or webcomponents)
- **Other libraries** out there **do too little**, focus on logging and have inconsistent ANSI handling *.
- **JS + Canvas** No binaries... we are 100% JS, with a common code path in browser and server †.
- It **works like a package manager** for figlet fonts.
- **flexible output** Supports 4bit, 8bit and 32bit output
- **Supports your existing API** We allow you to use the colors.js/chalk API *or* our own ‡.
* - Example: Style text, then put it in a table. It displays based on it's ansi string width, but balances cell widths based on the string width, leading to crazy looking output.
† - This allows us plug into averaging, distance and other logic dynamically, in powerful ways (In node this renders in cairo, via a Canvas shim)
‡ - while both have fluent apis we use a grid and are asynchronous, which enables large image processing and complex compositing scenarios, whereas the chalk API focuses on immediate string mutations
| `ascii-art` supports many usage styles, but the different use cases require slightly different installations. If you have any questions, please ask. | ||
In Code```bash npm install --save ascii-art ``` |
CLI```bash npm install -g ascii-art ``` or (Beta): ```bash npm install -g ascii-art-cl ``` |
Web```bash npm install --save ascii-art-webcomponents ``` |
| All chains in `ascii-art` can be called in one of 3 ways. In this example we change "Some Text" to be formatted using the `doom.flf` font. | ||
Callback```javascript art.font("Some Text", 'doom', (err, rendered)=>{ //if err, err is the error that occured //if !err rendered is the ascii }); ``` |
Promise```javascript art.font("Some Text", 'doom') .then((rendered)=>{ //rendered is the ascii })).catch((err)=>{ //err is an error })); ``` |
Await```javascript try{ let rendered = await art.font("Some Text", 'doom').completed() //rendered is the ascii }catch(err){ //err is an error } ``` |
| Change "Some Text" to be formatted with ansi codes for `green` (then have the colors reset at the end of the string) | ||
JS```javascript art.style("Some Text", 'green', true) //returns String ``` |
CL```bash ascii-art text -s green "Some Text" ``` |
Web
```html
|
| Change "Some Text" to be formatted using the `doom.flf` font, which it will load from the predefined location (defaults to `/Fonts`) | ||
JS```javascript art.font("Some Text", 'doom', true) //returns String ``` |
CL```bash ascii-art font -F doom "Some Text" ``` |
Web
```html
|
| This takes `myImage.jpg`, converts the colors to ansi backgrounds and then stipples the details at a threshold of 40 (of 255) using a higher resolution image and then renders that into a braille overlay in black(#000000) on top of the colors. | ||
JS```javascript art.image({ src: "myImage.jpg", rows:80, cols:80, stipple:"#000000", posterize: true, threshold:40 }, cb) ``` |
CL```bash ascii-art image posterized stippled --rows=80 --cols=80 --stipple="#000000" --threshold=40 myImage.jpg ``` |
Web
```html
|




| ### Downsampling and detail loss Because of the [resolution downsampling](https://en.wikipedia.org/wiki/Pixel#Sampling_patterns) from the [original dimensions](https://en.wikipedia.org/wiki/Image_resolution#Pixel_count) to the [destination width](https://en.wikipedia.org/wiki/Characters_per_line), some finer details may be lost. Plan accordingly. Here's an example of [some sequential art](https://en.wikipedia.org/wiki/Grendel_(comics)) in 256 color (primarily greyscale): | ||
Example
| ||
JS```javascript var art = require('ascii-art'); var Color = require('ascii-art-ansi/colors'); Color.is256 = true; art.image({ src: "node_modules/ascii-art/Images/grendel.jpg", alphabet:"blocks" }, cb); ``` |
CL```bash ascii-art image -B 8 -C rankedChannel -a blocks node_modules/ascii-art/Images/grendel.jpg ``` |
Web```html ``` |
### Color Modes
Multiple output modes are available including [4bit](https://en.wikipedia.org/wiki/Color_depth#4-bit_color), [8bit](https://en.wikipedia.org/wiki/8-bit_color), [32bit](https://en.wikipedia.org/wiki/Color_depth#Deep_color_(30-bit)) (equivalent to [24bit](https://en.wikipedia.org/wiki/Color_depth#True_color_(24-bit))). [16bit](https://en.wikipedia.org/wiki/Color_depth#High_color_(15/16-bit)) color was intentionally excluded, as there is no direct terminal support and the cost of including color definitions for such a large set would not be justified. It would be feasible to implement as an optional import, should the need exist.
The following example takes [`zero-cool.jpg`](https://www.youtube.com/watch?v=2efhrCxI4J0), converts the colors to ansi foreground color in solid block characters. Note that you will need to tune your distance function in 8bit mode, as what looks good varies by the type of imagery that goes through it.
Anecdotally, the default distance function only covers ~1/3 of the samples we've done, but we support many methods(`euclideanDistance`, `classic`, `ratioDistance`, `classicByValue`, `CIE76Difference`, `closestByIntensity`, `rankedChannel`, `simple`, `minDeviation`, `luminosity`, `saturation`, `hue`, `original`). But helpfully, you can merge algorithms by asking for `algorithm1+algorithm2` (it uses equal weighting), or make your own.
| |||
| img |
4
|
8
|
32
|
| JS |
4```javascript var art = require('ascii-art'); art.image({ src: "node_modules/ascii-art/Images/zero-cool.jpg", alphabet:"solid" }, cb); ``` |
8```javascript var art = require('ascii-art'); var Color = require('ascii-art-ansi/colors'); Color.is256 = true; art.image({ src: "node_modules/ascii-art/Images/zero-cool.jpg", alphabet:"solid" }, cb); ``` |
32```javascript var art = require('ascii-art'); var Color = require('ascii-art-ansi/colors'); Color.isTrueColor = true; art.image({ src: "node_modules/ascii-art/Images/zero-cool.jpg", alphabet:"solid" }, cb); ``` |
| CL |
4```bash ascii-art image -B 4 -a solid node_modules/ascii-art/Images/zero-cool.jpg ``` |
8```bash ascii-art image -B 8 -C closestByIntensity -a solid node_modules/ascii-art/Images/zero-cool.jpg ``` |
32```bash ascii-art image -B 32 -a solid node_modules/ascii-art/Images/zero-cool.jpg ``` |
| Web |
4
```html
|
8
```html
|
32
```html
|
| Render a table for with the provided data given the provided options | ||
JS```javascript art.table({}, cb) //returns String ``` |
CL```bash # N/A ``` |
Web```html ``` |
| Render a graph for with the provided data given the provided options | ||
JS```javascript art.graph({}, cb) //returns String ``` |
CL```bash # N/A ``` |
Web```html ``` |
| Fetch artwork from the requested source using the preconfigured request library. | ||
JS```javascript art.artwork({}, cb) //returns String ``` |
CL```bash # N/A ``` |
Web```html ``` |