Giter Club home page Giter Club logo

asciify-image's Introduction

asciify-image

Convert images to ASCII art without native dependencies

asciify-image allows you to convert images to ASCII art without native dependencies. This means that all you need to do is npm install ascii-image, instead of brewing and apt-geting other packages.

Features

  • Support for most common image types
  • Color and B/W
  • Numerous resizing options
  • CLI tool

Installing

Just install with npm:

$ npm install asciify-image

Or, if you want to use it directly in the command line:

$ npm install -g asciify-image

API

This API applies to asciify-image both as a Node.js module (example) and as a CLI tool. Use the -? or --help flag to see more about the CLI tool.

path

The file path, URL, or buffer for the image you wish to asciify. Currently supported formats are:

  • JPG
  • PNG
  • GIF

options.color

Default: true

If options.color is set to true, the asciified image will be in color when printed in your terminal. If set to false, the image will be in black and white.

options.fit

Default: 'original', CLI default: 'box'

The fit to resize the image to:

  • box - Resize the image such that it fits inside a bounding box defined by the specified width and height. Maintains aspect ratio.
  • width - Resize the image by scaling the width to the specified width. Maintains aspect ratio.
  • height - Resize the image by scaling the height to the specified height. Maintains aspect ratio.
  • original - Doesn't resize the image.
  • none - Scales the width and height to the specified values, ignoring original aspect ratio.

options.width

Default: original image width, CLI default: window width

The width to resize the image to. Use a percentage to set the image width to x% of the terminal window width.

options.height

Default: original image height, CLI default: window height

The height to resize the image to. Use a percentage to set the image height to x% of the terminal window height.

options.format

Default: 'string'

The format to return the asciified image in. Can be "string" or "array".

options.c_ratio

Default: 2

Since a monospace character is taller than it is wide, this property defines the integer approximation of the ratio of the width to height. You probably don't need to change this.

callback

The function to call after the image is asciified. Receives any errors that occurred as the first parameter and the asciified text as the second. When omitted, the module will return a Promise (example).

Examples

Using Callback Functions

var asciify = require('asciify-image');

var options = {
  fit:    'box',
  width:  200,
  height: 100
}

asciify('path/to/image.png', options, function (err, asciified) {
  if (err) throw err;

  // Print to console
  console.log(asciified);
});

Using Promises

var asciify = require('asciify-image');

var options = {
  fit:    'box',
  width:  200,
  height: 100
}

asciify('path/to/image.png', options)
  .then(function (asciified) {
    // Print asciified image to console
    console.log(asciified);
  })
  .catch(function (err) {
    // Print error to console
    console.error(err);
  });

How It Works

Images are represented by pixels. This package reads each pixel as an RGBa value. Each of these values is converted into a single integer, called "intensity". A darker pixel would have a higher intensity, and a lighter pixel would have a lower intensity.

For each pixel, a character is substituted: for a light pixel, the character "," may be substituted, but for a darker pixel, the character "8" would be substituted. Since these characters are different sizes, they look lighter or darker in the big picture (pun somewhat intended).

Some inspiration from image-to-ascii, but the code is written from scratch. Mostly created this because I didn't like the native dependencies required in existing asciification libraries.

asciify-image's People

Contributors

ajay-gandhi avatar dependabot[bot] avatar jpbm135 avatar kodie avatar lropero avatar ta2edchimp avatar uxkjaer 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

asciify-image's Issues

Can't specify height with `-h` option as CLI

-h option means --help.
But help message describes that -h means --height

$ asciify image.jpg -h 200

  Usage: asciify [options] [path]

  Options:

    -c, --color      true for color, false for B/W
    -r, --c-ratio    character width-height ratio
    -f, --fit        resize rule: box, height, width, original, none
    -h, --height     height to resize to
    -w, --width      width to resize to

  See the readme for detailed options and defaults

  Example:

    $ asciify lolwut.png -c false

Extra wide images don't get resized correctly

When trying to asciify an extra wide image such as this: http://placehold.it/620x140/ff00/00ff using the CLI tool, the image should get resized to fit the terminal, however it doesn't.

My image is 620 pixels wide by 140 pixel high.
My terminal is 125 columns wide by 25 rows high.

My image ends up looking like this:
screen shot 2018-01-08 at 10 17 17 am

However, if I set the c-ratio to 1, it comes out okay:
screen shot 2018-01-08 at 10 19 31 am

I'm not really sure why this happens and I'm going to do some more digging to see if I can come up with a solution but I figured I would document it on here.

isWindows

On importing import asciify from 'asciify-image'; , I get a Type error error saying: TypeError: isWindows is not a function

Remove `npm` from dependencies?

Hi, I've been using your library to log images under Node.js with good results, very helpful indeed when debugging WebGL related code running in headless mode.

However, a problem with this library is that it lists npm as a dependency which while unused, is just too heavy for our app installs. If you could move npm to devDependencies (or completely remove it from package.json) things would look much better.

https://github.com/ajay-gandhi/asciify-image/blob/master/package.json#L13

asciify-image can’t be installed on current node/npm on OSX 10.12.1 …

Hello there, unfortunately, asciify-image can’t be installed on current node/npm on OSX 10.12.1 … some problem with lwip and/or lodash. Could you maybe look into this? Thank you very much.

npm install asciify-image

[email protected] install node_modules/asciify-image/node_modules/lwip
node-gyp rebuild

 CXX(target) Release/obj.target/lwip_decoder/src/decoder/init.o
In file included from ../src/decoder/init.cpp:1:
In file included from ../src/decoder/decoder.h:13:
In file included from ../../nan/nan.h:182:
../../nan/nan_maybe_43_inl.h:221:17: warning: 'CloneElementAt' is deprecated [-Wdeprecated-declarations]
 return array->CloneElementAt(GetCurrentContext(), index);
               ^
/Users/and1/.node-gyp/7.0.0/include/node/v8.h:3056:36: note: 'CloneElementAt' has been explicitly marked deprecated here
               MaybeLocal<Object> CloneElementAt(Local<Context> context,
                                  ^
In file included from ../src/decoder/init.cpp:1:
In file included from ../src/decoder/decoder.h:13:
In file included from ../../nan/nan.h:188:
In file included from ../../nan/nan_new.h:189:
../../nan/nan_implementation_12_inl.h:40:29: warning: 'New' is deprecated [-Wdeprecated-declarations]
 return v8::BooleanObject::New(value).As<v8::BooleanObject>();
                           ^
/Users/and1/.node-gyp/7.0.0/include/node/v8.h:4048:56: note: 'New' has been explicitly marked deprecated here
 V8_DEPRECATED("Pass an isolate", static Local<Value> New(bool value));
                                                      ^
In file included from ../src/decoder/init.cpp:1:
In file included from ../src/decoder/decoder.h:13:
../../nan/nan.h:590:20: error: no type named 'GCEpilogueCallback' in 'v8::Isolate'
     v8::Isolate::GCEpilogueCallback callback
     ~~~~~~~~~~~~~^
../../nan/nan.h:596:20: error: no type named 'GCEpilogueCallback' in 'v8::Isolate'
     v8::Isolate::GCEpilogueCallback callback) {
     ~~~~~~~~~~~~~^
../../nan/nan.h:601:20: error: no type named 'GCPrologueCallback' in 'v8::Isolate'
     v8::Isolate::GCPrologueCallback callback
     ~~~~~~~~~~~~~^
../../nan/nan.h:607:20: error: no type named 'GCPrologueCallback' in 'v8::Isolate'
     v8::Isolate::GCPrologueCallback callback) {
     ~~~~~~~~~~~~~^
../../nan/nan.h:1927:15: warning: 'SetAccessor' is deprecated [-Wdeprecated-declarations]
 return obj->SetAccessor(
             ^
/Users/and1/.node-gyp/7.0.0/include/node/v8.h:2761:22: note: 'SetAccessor' has been explicitly marked deprecated here
               bool SetAccessor(Local<Name> name,
                    ^
3 warnings and 4 errors generated.
make: *** [Release/obj.target/lwip_decoder/src/decoder/init.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Darwin 16.1.0
gyp ERR! command "/usr/local/Cellar/node/7.0.0/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd node_modules/asciify-image/node_modules/lwip
gyp ERR! node -v v7.0.0
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok
./
└── (empty)

npm WARN enoent ENOENT: no such file or directory, open ‘./package.json'
npm ERR! Darwin 16.1.0
npm ERR! argv "/usr/local/Cellar/node/7.0.0/bin/node" "/usr/local/bin/npm" "install" "asciify-image"
npm ERR! node v7.0.0
npm ERR! npm  v3.10.8
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the lwip package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs lwip
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls lwip
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     npm-debug.log
npm ERR! code 1

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.