Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/aromalanil/get-ascii-image

๐Ÿ’ผ A zero dependency npm package for the web๐ŸŒ to convert images ๐Ÿ–ผ to ASCII.
https://github.com/aromalanil/get-ascii-image

ascii-generator ascii-image characters frontend-library image-manipulation image-processing image-to-ascii

Last synced: 4 months ago
JSON representation

๐Ÿ’ผ A zero dependency npm package for the web๐ŸŒ to convert images ๐Ÿ–ผ to ASCII.

Awesome Lists containing this project

README

        


Cover Image

get-ascii-image


A zero dependency image to ascii convertor for Web๐ŸŒ






npm


npm Downloads/Week


GitHub issues


npm bundle size


GitHub License



> Note : **This is a frontend only package**, As this package uses Canvas API of the DOM.


## ๐Ÿงฐ Installation

### Using npm or yarn ๐Ÿ“ฆ

```bash
# Using npm
npm i get-ascii-image

# Using yarn
yarn add get-ascii-image
```

### Using CDN โšก

Include the js script in your `head` tag as follows:

```html

```

Or you can download the package from [here](https://github.com/aromalanil/get-ascii-image/archive/master.zip), extract it and include the path to the `index.js` in your `head` tag

```html

```

## ๐Ÿฐ Example

```js
import getAsciiImage from "get-ascii-image";

const imageURL = 'https://example.com/image.jpg';

const config = {
maxWidth:100,
maxHeight:300
};

getAsciiImage(imageURL,config)
.then(ascii=>{
document.getElementById('image-container').innerText = ascii;
})
.catch(err=>{
console.log(err);
}
});
```

## ๐Ÿงต Syntax

### Using async-await โœ‹๐Ÿป

```js
import getAsciiImage from "get-ascii-image";

let asciiImage;

//inside an async function
try {
//Returns Ascii Image as a string
asciiImage = await getAsciiImage(imageSource, config);
} catch (err) {
console.log(err);
}
```

### Using Promise ๐Ÿค๐Ÿป

```js
import getAsciiImage from "get-ascii-image";

let asciiImage;

getAsciiImage(imageSource, config)
.then((ascii) => {
asciiImage = ascii;
})
.catch((err) => {
console.log(err);
});
```

## ๐Ÿฌ Parameters

- `imageSource` (_String_) : The absolute path to the image source.

- `config` (_Function_) : Optional. An object with 3 values namely `maxWidth` and `maxHeight` and `avoidedCharacters`.

## ๐Ÿ”ง Configuration

Pass the configurations to the function using the `config` parameter. The `config` is an object which can contain the following values.

- `maxWidth` (_number_) : Maximum ascii characters in one row of generated Ascii image. Default value is 300
- `maxHeight` (_number_) : Maximum ascii characters in one column of generated Ascii image . Default value is 500
- `avoidedCharacters` (_String Array_) : Add all characters you want to avoid in the output, to this array.

Here is an example of a `config` object :

```js
const config = {
maxWidth: 400,
maxHeight: 700,
avoidedCharacters: ["#", "a"],
};
```

## ๐Ÿ”— Miscellaneous

- In case you are taking the image from an external link, make sure the response to the link request contains the header `Access-Control-Allow-Origin: *` in it.

## ๐Ÿ“œ License

```
MIT License

Copyright (c) 2020 Aromal Anil

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

## โœ๐Ÿป Author

[Aromal Anil](https://aromalanil.me)