get-ascii-image
v1.3.6
Published
Frontend only package, which converts image source into ASCII art
Downloads
43
Maintainers
Readme
Note : This is a frontend only package, As this package uses Canvas API of the DOM.
🧰 Installation
Using npm or yarn 📦
# 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:
<script src="https://unpkg.com/get-ascii-image/index.js" />
Or you can download the package from here, extract it and include the path to the index.js
in your head
tag
<script src="path/to/get-ascii-image/index.js" />
🍰 Example
const getAsciiImage = require('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 ✋🏻
const getAsciiImage = require("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 🤝🏻
const getAsciiImage = require("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 namelymaxWidth
andmaxHeight
andavoidedCharacters
.
🔧 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 300maxHeight
(number) : Maximum ascii characters in one column of generated Ascii image . Default value is 500avoidedCharacters
(String Array) : Add all characters you want to avoid in the output, to this array.
Here is an example of a config
object :
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.