Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/aromalanil/get-ascii-image
- Owner: aromalanil
- License: mit
- Created: 2020-08-26T15:58:19.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-09-28T06:42:06.000Z (over 4 years ago)
- Last Synced: 2024-10-04T17:47:23.413Z (4 months ago)
- Topics: ascii-generator, ascii-image, characters, frontend-library, image-manipulation, image-processing, image-to-ascii
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/get-ascii-image
- Size: 296 KB
- Stars: 9
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
> 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 LicenseCopyright (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)