Giter Site home page Giter Site logo

mikeralphson / ansir-js Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 242 KB

Convert PNG/JPEG/GIFs to colourful terminal ANSI art. Based on

Home Page: https://github.com/themadcreator/ansir

License: Apache License 2.0

JavaScript 100.00%
png image bbs ansi ansi-art jpg jpeg gif

ansir-js's Introduction

ANSIR

Build Status

Generate UTF-8 Art from PNG using ANSI color codes.

Similar to oldschool ANSI art, we use UTF-8 block characters and standard terminal color escape sequences.

Supports both the basic and extended ANSI color escape sequences. Note: Full 24-bit RGB escape sequences currently not supported.

A utility conv.js can be used to convert JPEGs etc to PNG format.

Installation

npm install -g ansir

Generate artwork

ansir sample/in.png

Proportionally rescale the png file on the fly

ansir --scale 0.1 sample/in.png > sample/out.ans

Sample

Input

input

Output (10% scale)

output

Renderers

Ansir supports 3 modes of rendering, shown in the following table:

Block Shaded Sub
block shaded sub

Usage

  Usage: ansir <png>

  Generate UTF-8 Art from PNG using ANSI color codes.

  Options:

    -h, --help                 output usage information
    -s, --scale <float>        Proportionally rescale image
    -w, --width <integer>      Target output width (in characters)
    -h, --height <integer>     Target output height (in lines)
    --colors <basic|extended>
        The ANSI colorspace. Use "basic" for the most compatible 8-color
        palette. The default is "extended" for the 256-color palette supported by
        most major terminals that have any color at all.
    --background <light|dark>
        Applies only to "shaded" mode. Specifies whether the target terminal
        will have a light or dark background. This determines color matching for
        shaded UTF-8 block characters. Default is "dark", which means we interpret
        a shaded block character as darker than a solid one.
    --alpha-cutoff <float>
        The minimum alpha value of a pixel that should be converted to a ansi
        color utf-8 block character. Valid values are 0.0-1.0. Default is
        0.95.
    --mode <block|shaded|sub>
        The rendering mode. Default is "block". The options are:

        "block" - Use the ANSI background escape sequence to create seamless blocks.

        "shaded" - Use the ANSI foreground escape sequence on unicode block character.
          ░ LIGHT SHADE
          ▒ MEDIUM SHADE
          ▓ DARK SHADE
          █ FULL BLOCK

        "sub" - Use the ANSI foreground escape sequence on unicode quadrant block
                characters. NOTE: These characters can cause slowness when used
                with some common terminal fonts such as Consolas.
          ▘ QUADRANT UPPER LEFT
          ▝ QUADRANT UPPER RIGHT
          ▖ QUADRANT LOWER LEFT
          ▗ QUADRANT LOWER RIGHT
          ▚ QUADRANT UPPER LEFT AND LOWER RIGHT
          ▞ QUADRANT UPPER RIGHT AND LOWER LEFT
          █ FULL BLOCK

Resources

https://en.wikipedia.org/wiki/ANSI_art

http://ascii-table.com/ansi-escape-sequences.php

ansir-js's People

Contributors

mikeralphson avatar themadcreator avatar

Stargazers

 avatar

Watchers

 avatar  avatar

ansir-js's Issues

Error: Unknown ANSI color space undefined

Hi, I'm using Ubuntu 20.04 and node v17.4.0, npm version 8.4.1.

No matter what args I try to launch ansir with, I get the following stack trace (using your provided graphic):

/home/user/.nvm/versions/node/v17.4.0/lib/node_modules/ansir/src/config.coffee:17
          throw new Error("Unknown ANSI color space " + options.colors);
          ^

Error: Unknown ANSI color space undefined
    at /home/user/.nvm/versions/node/v17.4.0/lib/node_modules/ansir/src/config.coffee:8:16
    at configure (/home/user/.nvm/versions/node/v17.4.0/lib/node_modules/ansir/src/config.coffee:5:15)
    at Command.<anonymous> (/home/user/.nvm/versions/node/v17.4.0/lib/node_modules/ansir/ansir-cli.coffee:49:14)
    at Command.listener [as _actionHandler] (/home/user/.nvm/versions/node/v17.4.0/lib/node_modules/ansir/node_modules/commander/lib/command.js:480:17)
    at /home/user/.nvm/versions/node/v17.4.0/lib/node_modules/ansir/node_modules/commander/lib/command.js:1234:65
    at Command._chainOrCall (/home/user/.nvm/versions/node/v17.4.0/lib/node_modules/ansir/node_modules/commander/lib/command.js:1151:12)
    at Command._parseCommand (/home/user/.nvm/versions/node/v17.4.0/lib/node_modules/ansir/node_modules/commander/lib/command.js:1234:27)
    at Command.parse (/home/user/.nvm/versions/node/v17.4.0/lib/node_modules/ansir/node_modules/commander/lib/command.js:889:10)
    at Object.<anonymous> (/home/user/.nvm/versions/node/v17.4.0/lib/node_modules/ansir/ansir-cli.coffee:56:11)
    at Object.<anonymous> (/home/user/.nvm/versions/node/v17.4.0/lib/node_modules/ansir/ansir-cli.coffee:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1097:14)
    at Object.loadFile (/home/user/.nvm/versions/node/v17.4.0/lib/node_modules/ansir/node_modules/coffee-script/lib/coffee-script/register.js:16:19)
    at Module.load (/home/user/.nvm/versions/node/v17.4.0/lib/node_modules/ansir/node_modules/coffee-script/lib/coffee-script/register.js:45:36)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/user/.nvm/versions/node/v17.4.0/lib/node_modules/ansir/ansir-cli.js:6:3)
    at Module._compile (node:internal/modules/cjs/loader:1097:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47


Node.js v17.4.0

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.