Coder Social home page Coder Social logo

khrome / ascii-art Goto Github PK

View Code? Open in Web Editor NEW
684.0 13.0 286.0 4.04 MB

A Node.js library for ansi codes, figlet fonts, ascii art and other ASCII graphics

License: MIT License

JavaScript 99.21% Shell 0.79%
javascript ascii-art ansi-styles ascii ansi-codes tables figlet images compositing terminal-graphics

ascii-art's Introduction

                   _  _                       _
                  (_)(_)                     | |
  __ _  ___   ___  _  _  ______   __ _  _ __ | |_
 / _` |/ __| / __|| || ||______| / _` || '__|| __|
| (_| |\__ \| (__ | || |        | (_| || |   | |_
 \__,_||___/ \___||_||_|         \__,_||_|    \__|

ascii-art.js

NPM version npm Travis GitHub stars

Images, fonts, tables, ansi styles and compositing in Node.js & the browser. 100% JS. (What is ASCII-Art?)

In the beginning there was colors.js but in the fine tradition of vendors calling out a problem they have the solution to, chalk was introduced. In that same vein, I offer ascii-art as an update, expansion and generalization of MooAsciiArt and at the same time it can replace your existing ansi colors library.

It features support for Images, Styles, Tables, Graphs and Figlet Fonts as well as handling multi-line joining and compositing automatically.

Why would I use this?

[click to expand/close]

  • 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 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

Installation

ascii-art supports many usage styles, but the different use cases require slightly different installations. If you have any questions, please ask.

In Code

    npm install --save ascii-art

CLI

    npm install -g ascii-art

or (Beta):

    npm install -g ascii-art-cl

Web

    npm install --save ascii-art-webcomponents

Call Style

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

    art.font("Some Text", 'doom', (err, rendered)=>{
        //if err, err is the error that occured
        //if !err rendered is the ascii
    });

Promise

    art.font("Some Text", 'doom')
       .then((rendered)=>{
           //rendered is the ascii
       })).catch((err)=>{
           //err is an error
       }));

Await

    try{
        let rendered = await art.font("Some Text", 'doom').completed()
        //rendered is the ascii
    }catch(err){
        //err is an error
    }

Styles

Add ANSI styles to a string and return the result.

Change "Some Text" to be formatted with ansi codes for green (then have the colors reset at the end of the string)

JS

    art.style("Some Text", 'green', true) //returns String

CL

    ascii-art text -s green "Some Text"

Web

    <ascii-art-style
		style="green"
	>Some Text</ascii-art-style>

Styles are: italic, bold, underline, |framed|, |encircled|, overline, blink and  inverse . And available colors are:

Colors

Color defaults to 8 bit (most compatible), to enable other modes set booleans in the options:

  • is256 : compute the color using 256colors, as defined by ansi256. Note that full color output may need to tune the difference method to obtain optimal results.
  • isTrueColor : do not constrain color and directly output RGB to the console.

Color Tables may be found in the style documentation

Fonts

Render a string using a figlet font and add that to the buffer. There is a batch version of this function which does not chain and takes an array( .strings()).

Change "Some Text" to be formatted using the doom.flf font, which it will load from the predefined location (defaults to /Fonts)

JS

    art.font("Some Text", 'doom', true) //returns String

CL

    ascii-art font -F doom "Some Text"

Web

    <ascii-art-font
		font="doom"
	>Some Text</ascii-art-font>

Outputs

______                          _
|  _  \                        | |
| | | |  ___  _ __ ___    ___  | |
| | | | / _ \| '_ ` _ \  / _ \ | |
| |/ / |  __/| | | | | || (_) ||_|
|___/   \___||_| |_| |_| \___/ (_)

UTF Fonts

If you use UTF fonts(Which are part of your system fonts) your output looks more like: Gothic UTF font or Sans Serif UTF font by using u:<utf font name> where the font names are: default, script, script+bold, gothic, gothic+bold, serif+bold+italic, serif+bold, serif+italic, monospace, sansserif, sansserif+bold+italic, sansserif+bold, sansserif+italic, doublestrike

Check out the documentation for more examples!

Images

Create an image from the passed image and append that to the buffer

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

    art.image({
        src: "myImage.jpg",
        rows:80,
        cols:80,
        stipple:"#000000",
        posterize: true,
        threshold:40
    }, cb)

CL

    ascii-art image posterized stippled
        --rows=80 --cols=80 --stipple="#000000"
        --threshold=40 myImage.jpg

Web

    <ascii-art-image
        src="myImage.jpg"
        rows="80" cols="80"
        stipple="#000000"
        posterize
        threshold="40"
    ></ascii-art-image>

There are some options that are available which are not in the image core, they are:

  • lineart : A boolean option which outputs lineart using block characters (which may be colored with stroke and customized with threshold(0-255)).

    Example

  • stipple : A boolean option which outputs lineart using braille characters (which may be colored with stroke and customized with threshold(0-255)).

    Example

  • posterize : Use stipple on top of colored backgrounds to retain as much detail as possible.

    Example

  • blended : Use posterize with both lineart and braille at relative thresholds to each other.

    Example

Downsampling and detail loss

Because of the resolution downsampling from the original dimensions to the destination width, some finer details may be lost. Plan accordingly. Here's an example of some sequential art in 256 color (primarily greyscale):

Example

JS

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

    ascii-art image
        -B 8
        -C rankedChannel
        -a blocks
        node_modules/ascii-art/Images/grendel.jpg

Web

    <!-- todo -->

Color Modes

Multiple output modes are available including 4bit, 8bit, 32bit (equivalent to 24bit). 16bit 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, 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

var art = require('ascii-art');
art.image({
    src: "node_modules/ascii-art/Images/zero-cool.jpg",
    alphabet:"solid"
}, cb);

8

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

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

    ascii-art image
       -B 4
       -a solid
       node_modules/ascii-art/Images/zero-cool.jpg

8

    ascii-art image
       -B 8
       -C closestByIntensity
       -a solid
       node_modules/ascii-art/Images/zero-cool.jpg

32

    ascii-art image
       -B 32
       -a solid
       node_modules/ascii-art/Images/zero-cool.jpg

Web
4

<ascii-art-image
    src="node_modules/ascii-art/Images/zero-cool.jpg"
    rows="80" cols="80"
    alphabet="solid"
    bit-depth="4"
></ascii-art-image>

8

<ascii-art-image
    src="node_modules/ascii-art/Images/zero-cool.jpg"
    rows="80" cols="80"
    alphabet="solid"
    bit-depth="8"
    color-distance="closestByIntensity"
></ascii-art-image>

32

<ascii-art-image
    src="node_modules/ascii-art/Images/zero-cool.jpg"
    rows="80" cols="80"
    alphabet="solid"
    bit-depth="32"
></ascii-art-image>

Check out the documentation for more examples!

Tables

Generate a table from the passed data, with support for many styles and append that to the buffer

Render a table for with the provided data given the provided options

JS

    art.table({}, cb) //returns String

CL

    # N/A

Web

    <!--N/A -->

Styled Table Example

Check out the documentation for more examples!

Graphs

Render a graph for with the provided data given the provided options

JS

    art.graph({}, cb) //returns String

CL

    # N/A

Web

    <!--N/A -->

Graph Example

Check out the documentation for more examples!

Artwork[Non-Functional]

Fetch a graphic from a remote source and append it to the current buffer, which is not enabled by default. You must add a request compatible library by either setting the ENV variable ASCII_ART_REQUEST_MODULE or by setting it manually with art.setRequest(requestModule)

Fetch artwork from the requested source using the preconfigured request library.

JS

    art.artwork({}, cb) //returns String

CL

    # N/A

Web

    <!--N/A -->

Often I use this in conjunction with an image backdrop, for example to superimpose bones on the earth:

Mixed Content Example

Compositing

We also support combining all these nifty elements you've made into a single composition, via a few functions available on the chains (.lines(), .overlay(), .border(), .strip() and .join()). Maybe I've got A BBS wall I want to have some dynamic info on.. I could make that with this

Mixed Content Example

Check out the documentation for detailed examples!

Compatibility

If you're a chalk user, just use var chalk = require('ascii-art/kaolin'); in place of your existing chalk references (Much of color.js, too... since chalk is a subset of colors.js). No migration needed, keep using the wacky syntax you are used to(In this mode, refer to their docs, not mine).

Users of ascii-table will also note that interface is supported via require('ascii-art').Table, though our solution is ansi-aware, lazy rendering and better at sizing columns.

I may support the other colors stuff (extras & themes) eventually, but it's currently a low priority.

Roadmap

Goals

  • Re-enable .artwork()
  • Bring karma current, deprecate phantomjs
  • artwork source standard
  • Better Docs
  • value reversal (light vs dark)
  • HTML output
  • piping support on the command line
  • ATASCII art support
  • ANSI art support
  • PETSCII art support
  • 2 colors per char with multisampling
  • Graph enhancements
  • REPL

Non Goals

  • realtime: videos, curses, etc.:
  • logging integration

Testing

In the root directory run:

npm run test

which runs the test suite directly. In order to test it in Chrome try:

npm run browser-test

In order to run the chalk test, use:

npm run chalk-test

Deprecations

  • .artwork() is currently non-functional while we enable an open-plugin standard, which will arrive shortly. When it does, you'll be able to plug any number of fetch solutions in, which hopefully matches whatever you currently bundle.
  • .toPromise() is now deprecated in favor of .completed() and will be removed when 3.x arrives
  • up to this point all files are UMD wrapped and may be used without modification in node(even old versions), the browser and via browser build systems. when 3.x arrives, the UMD versions may be part of an independent build process, while the mainline browser and node versions may continue to be uniform. If you have opinions on this, I'd like to hear them.

Development

How to dev : the simple version

  • fork ascii-art
  • git clone [email protected]:<YOUR GITHUB USERNAME>/ascii-art.git
  • go into the checked out module cd ascii-art
  • execute ./test/dev_setup.sh (this will install a number of dependencies in the parent directory)

How to dev : a better version

  • Fork all the ascii-art-modules(ascii-art-image, ascii-art-ansi, ascii-art-braille, ascii-art-docs, ascii-art-font, ascii-art-utf, ascii-art-graph, ascii-art-table), along with the root module.
  • git clone [email protected]:<YOUR GITHUB USERNAME>/ascii-art.git
  • go into the checked out module cd ascii-art
  • ./dev_setup.sh <YOUR GITHUB USERNAME>
  • commit to your own branches master, then submit PRs from that to the master branch of the main repo.

After setup, run npm test to make sure everything is working correctly.

Note various modern editions of npm nuke links each time package-lock.json is written (which, depending on your settings, may be every new dependency you add). This can be remedied by executing npx module-auto-link -c 'npm-auto-link' in the module in question, which will restore it's links.

Please make sure to run the tests before submitting a patch and report any rough edges. Thanks!

Enjoy,

-Abbey Hawk Sparrow

ascii-art's People

Contributors

daawesomep avatar khrome avatar lukaselmer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ascii-art's Issues

Increase color depth?

Is there a functional difference between this lib and ascii-art-image?

I got ascii-art-image working, although the color palette is.... pretty bad on iTerm2 and I can't get it to display a better looking image unfortunately for a passed in RGB png file:

    var image = new Image({
        filepath: '/users/admin/images/candle.png',
        alphabet: 'blocks',
    });

    image.write(function(err, rendered){
        console.log(rendered);
    })

Original:
image

Output:
CleanShot 2023-05-22 at 16 23 10@2x

Add basic use in README.md

Sometimes modules don't use the name you expect them to.

Your examples use art but the name is ascii-art.

I had to search in your code to solve this riddle.

var art = require('ascii-art');

How do I use this in [browser or browser framework]?

I frequently get asked how to do ascii-art for the web (beyond dumping actual ansi strings in console.log(), which works in some browsers), but the work for this is significant, and I've never been sold on a pure JS approach in the browser, unless you have a hefty framework backing you up. But recently WebComponents support has finally closed the gap enabling a simple solution for anyone using a browser.

So go right here, test it out and file bugs/ask questions.

How do I use this in reactjs?

Can you please provide a new or existing example of using this with reactjs and outputting the art to the console? Currently I have a static txt file which contains ascii.

example.js tiny bug

There is a tincy tiny bug in the example.js:

The example looks like this:
art.font('Demo!', 'Doom', function(rendered){ console.log(art.style(rendered, 'blue_bg+red+blink+inverse')); });

But the implementation looks like:
AsciiArt.font = function(str, fontName, style, callback)

ie. In the example the "style" parameter is never set, causing things to behave unexpected.
Working example:

var style = null; // or use an actual style
art.font('Demo!', 'Doom', style, function(rendered){ console.log(art.style(rendered, 'blue_bg+red+blink+inverse')); });

Security issue

Hello,

As a member of the Node.js Security WG
I would like to draw your attention to a security report that has been made regarding this issue.

I have made attempts to contact the person identified as a maintainer of this package but did not get any answer. What is the best way to reach someone with commit rights over this repo and hopefully npm publishing rights as well, in order to invite them to privately discuss the issue on the HackerOne platform and provide a resolution?

Thanks,
Liran.

References:

Hosted API

Hey @khrome 👋 Thanks for creating such a cool ascii art library.

I'm looking to convert open source libs into SaaS APIs as part of my work with saasify.sh and thought ascii-art would be a great fit.

Ideally I'd create an API endpoint to generate ascii art along the lines of

https://api.saasify.sh/1/call/dev/ascii-art@latest/art

where a JSON payload would build your chain of operations (lifted from one of your examples)

{
  "ops": [
    {
      "type": "image",
      "width": 40,
      "url": "https://example.com/Images/initech.png",
      "alphabet": "wide"
    },
    {
      "type": "font",
      "text": "Doom",
      "color": "cyan"
    }
  ]
}

We'd love to offer a rate-limited API and reserve most of the profits for you. As an example, we've also worked on converting sindresorhus' imagemin and minimaxir's stylecloud to APIs.

Looking forward to hearing your thoughts! Would also be happy to jump on a quick call to discuss.

Update canvas

Please update your version of canvas, the version used here is not supported in node v12/13.

Replace [email protected] by [email protected] (or latest)

Hello,

✗ Medium severity vuln found in [email protected], introduced via [email protected]
Description: Uninitialized Memory Exposure
Info: https://snyk.io/vuln/npm:tunnel-agent:20170305
From: [email protected] > [email protected] > [email protected]

✗ Medium severity vuln found in [email protected], introduced via [email protected]
Description: Insecure Randomness
Info: https://snyk.io/vuln/npm:cryptiles:20180710
From: [email protected] > [email protected] > [email protected] > [email protected]

Regards,

Module not found: Can't resolve 'fs'

I did a yarn add ascii-art in my project, added window.art = require('ascii-art'); and tried to build using npm run build but it gives the following error:

Module not found: Can't resolve 'fs' in 'C:....\node_modules\ascii-art-image'

I am not so great with these tools so it can be something at my end that I am doing wrong.

Security updates in deps

[email protected] has a couple of dependency updates, that should be updated due to a high risk, due to the version of d3-color and cli for this package. This is the result of running an audit on the package.

┌─────────────────────┬────────────────────────────────────────────────────────┐
│ high                │ d3-color vulnerable to ReDoS                           │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Package             │ d3-color                                               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Vulnerable versions │ <3.1.0                                                 │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Patched versions    │ >=3.1.0                                                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Paths               │ . > [email protected] > [email protected] >          │
│                     │ [email protected] > [email protected] > [email protected] >    │
│                     │ [email protected]                                         │
│                     │                                                        │
│                     │ . > [email protected] > [email protected] >          │
│                     │ [email protected] > [email protected] > [email protected] >     │
│                     │ [email protected]                                         │
│                     │                                                        │
│                     │ . > [email protected] > [email protected] >          │
│                     │ [email protected] > [email protected] > [email protected] >     │
│                     │ [email protected] > [email protected]                  │
│                     │                                                        │
│                     │ ... Found 13 paths, run `pnpm why d3-color` for more   │
│                     │ information                                            │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ More info           │ https://github.com/advisories/GHSA-36jr-mh4h-2g58      │
└─────────────────────┴────────────────────────────────────────────────────────┘
┌─────────────────────┬────────────────────────────────────────────────────────┐
│ low                 │ Arbitrary File Write in cli                            │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Package             │ cli                                                    │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Vulnerable versions │ <1.0.0                                                 │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Patched versions    │ >=1.0.0                                                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Paths               │ . > [email protected] > [email protected] >           │
│                     │ [email protected] > [email protected]                     │
│                     │                                                        │
│                     │ . > [email protected] > [email protected] >          │
│                     │ [email protected] > [email protected] >        │
│                     │ [email protected]                                              │
│                     │                                                        │
│                     │ . > [email protected] > [email protected] >          │
│                     │ [email protected] > [email protected] >        │
│                     │ [email protected]                                              │
│                     │                                                        │
│                     │ ... Found 5 paths, run `pnpm why cli` for more         │
│                     │ information                                            │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ More info           │ https://github.com/advisories/GHSA-6cpc-mj5c-m9rq      │
└─────────────────────┴────────────────────────────────────────────────────────┘
┌─────────────────────┬────────────────────────────────────────────────────────┐
│ low                 │ Node CLI Allows Arbitrary File Overwrite               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Package             │ cli                                                    │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Vulnerable versions │ >=0.1.0 <=0.11.3                                       │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Patched versions    │ >=1.0.0                                                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Paths               │ . > [email protected] > [email protected] >           │
│                     │ [email protected] > [email protected]                     │
│                     │                                                        │
│                     │ . > [email protected] > [email protected] >          │
│                     │ [email protected] > [email protected] >        │
│                     │ [email protected]                                              │
│                     │                                                        │
│                     │ . > [email protected] > [email protected] >          │
│                     │ [email protected] > [email protected] >        │
│                     │ [email protected]                                              │
│                     │                                                        │
│                     │ ... Found 5 paths, run `pnpm why cli` for more         │
│                     │ information                                            │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ More info           │ https://github.com/advisories/GHSA-3mrp-qhcj-mwv5      │
└─────────────────────┴────────────────────────────────────────────────────────┘

This does not install non-contributed fonts

Using Mac, with High Sierra, Node v9.6.1 (and any previous version), and up-to-date install of ascii-art

These work:
ascii-art install chunky
ascii-art install hex

Most others fail, e.g.:
ascii-art install big
ascii-art install block
ascii-art install bubble

Please can you look into this? The fonts are available for manual download and installation from the figlet website.

types are incomplete

const r = await art.font("Hello World", "Doom").completed(); this code actually works but according to your ts types it says that completed isnt actually function

How to use more colors converting from image?

It is not clear how to use more colors when converting an image to ASCII art. For example, this:

$ ascii-art image file.png

and this:

var art = require('ascii-art');

var image = new art.Image({
	filepath: 'file.png'
});
image.write(function(err, rendered){
	console.log(rendered);
})

produce ASCII art with few colors.

root.Image is not a constructor

Hello, I'd love to create a panel for Adobe Illustrator and Photoshop which uses this module internally, and in following the code found in image-core:

var Image = require('ascii-art-image');
 
var image = new Image({
    filepath: '~/Images/metropolis.jpg',
    alphabet:'variant4'
});
 
image.write(function(err, rendered){
    console.log(rendered);
})

Like so:

// within a Vue component's methods
    generateAscii(path) {
      let Image = require("ascii-art-image");
      let image = new Image({
        filepath: path,
        alphabet: "variant4"
      });

      image.write((err, rendered) => {
        console.log(rendered);
      });
    }

Or:

    generateAscii(path) {
      let ascii = require("ascii-art");
      let image = ascii.Image({
        filepath: path,
        alphabet: "variant4"
      });
    }

I get an error claiming root.Image is not a constructor:

webpack-internal:///./node_modules/vue/dist/vue.runtime.esm.js:1887 TypeError: root.Image is not a constructor
    at imgLoadBrowser (webpack-internal:///./node_modules/ascii-art-image/image.js:3:19)
    at new AsciiArt.Image (webpack-internal:///./node_modules/ascii-art-image/image.js:82:13)
    at generateAscii$ (webpack-internal:///./node_modules/babel-loader/lib/index.js?!./node_modules/@quasar/app/lib/webpack/loader.auto-import.js?kebab!./node_modules/vue-loader/lib/index.js?!./src/pages/Index.vue?vue&type=script&lang=js&:126:23)
    at tryCatch (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:45:40)
    at Generator.invoke [as _invoke] (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:271:22)
    at Generator.prototype.(anonymous function) [as next] (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:97:21)
    at tryCatch (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:45:40)
    at invoke (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:135:20)
    at eval (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:170:11)
    at new Promise (<anonymous>)

I've tried making sure to install canvas and reinstall both ascii-art or ascii-art-image, but am unsure of what to do here. Can the documentation be updated or I be corrected on how to do this?

stipple doesn't seem to be supported in non-cli version

so i have the call to ascii-art:

art.image({
            stippled: true,
            filepath: file,
            threshold: 128,
            width: 32,
            height: 32
          });

and when the art is logged to the console it appears like this:
image

and when i save to a file it gets rendered in notepad++ as:
image

i'm basically trying to put some stippled ascii art in a subtitle file, fwiw.

windows 10, most recent version of ascii-art on npm.

Can't find yargs

Error: Cannot find module 'yargs'
Require stack:
- /usr/lib/node_modules/ascii-art/bin/ascii-art
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/usr/lib/node_modules/ascii-art/bin/ascii-art:3:13)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/usr/lib/node_modules/ascii-art/bin/ascii-art' ]

Error trying to use art.Image

While trying to use art.Image like this:

const art = require('ascii-art');
let image = new art.Image({
	filepath: __dirname + '\\l.jpg',
	alphabet:'hatching'
});

I get this error:

C:\Users\tj\Desktop\TestProjectDoer\node_modules\ascii-art\image.js:109
                ob.canvas = new Canvas(ob.image.width, ob.image.height);
                            ^

TypeError: Canvas is not a constructor
    at C:\Users\tj\Desktop\TestProjectDoer\node_modules\ascii-art\image.js:109:29
    at C:\Users\tj\Desktop\TestProjectDoer\node_modules\ascii-art\image.js:30:17
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:490:3)

I have ascii-art version 1.4.2 and node-canvas version 2.0.0-alpha.11
I have tried rebuilding canvas and reinstalling both modules, so far nothing has worked.

chalk compatibility

Many app developers use chalk and colour, support those interfaces for drop-in replacement.

Also clarify how ascii-art supports block formatting without formatter wrapping (showing mangled examples from other popular libs).

[ERROR] No loader is configured for ".node" files: node_modules/canvas/build/Release/canvas.node

Using this library in a TypeScript app with esbuild, see the below error,

$ /home/ubuntu/environment/checker/node_modules/.bin/esbuild --bundle /home/ubuntu/environment/checker/src/lambda.d/checker/index.ts --target=node14 --platform=node --outfile=/home/ubuntu/environment/checker/cdk.out/bundling-temp-a5c74f113b8c87a1a34f41dde7ae72eba852d1bccfbaa6b6573360a5e136168d/index.js --external:aws-sdk
✘ [ERROR] No loader is configured for ".node" files: node_modules/canvas/build/Release/canvas.node

    node_modules/canvas/lib/bindings.js:3:25:
      3 │ module.exports = require('../build/Release/canvas.node')
        ╵                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1 error
child_process.js:830
    throw err;
    ^

Error: Command failed: /home/ubuntu/environment/checker/node_modules/esbuild-linux-64/bin/esbuild --bundle /home/ubuntu/environment/checker/src/lambda.d/checker/index.ts --target=node14 --platform=node --outfile=/home/ubuntu/environment/checker/cdk.out/bundling-temp-a5c74f113b8c87a1a34f41dde7ae72eba852d1bccfbaa6b6573360a5e136168d/index.js --external:aws-sdk
    at checkExecSyncError (child_process.js:790:11)
    at Object.execFileSync (child_process.js:827:15)
    at Object.<anonymous> (/home/ubuntu/environment/checker/node_modules/esbuild/bin/esbuild:109:26)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47 {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 4825,
  stdout: null,
  stderr: null
}
error Command failed with exit code 1.

Any hint to resolve it?

no output from image with node v14.18.0

I try code like this, but I get nothing. I don't get an error, but there's no output to the screen.


var art = require("ascii-art")

art.image({
        src: "file:///home/dave/Pictures/nyt.png",
        rows:80,
        cols:80,
        stipple:"#000000",
        posterize: true,
        threshold:40
    }, (err, rendered) => {

      console.log(err,rendered);
    })

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.