GithubHelp home page GithubHelp logo

khrome / ascii-art Goto Github PK

View Code? Open in Web Editor NEW
688.0 688.0 287.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%
ansi-codes ansi-styles ascii ascii-art command-line-tool compositing figlet images javascript tables terminal-graphics

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

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.

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.

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

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);
    })

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.

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.

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');

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,

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.

[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?

Update canvas

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

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      │
└─────────────────────┴────────────────────────────────────────────────────────┘

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).

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:

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.

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

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.

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')); });

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?

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.

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' ]

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.