char-dust
Convert image to char.
Usage
yarn add char-dust
# npm install char-dust
Browser
<img id="demo-image" src="xxx" />
import { imageToText, getImageData } from "char-dust";
const imageElement = document.getElementById("demo-image");
const imageData = getImageData(imageElement);
// const text = imageToText(imageData);
// default is "@#&$%863!i1uazvno~;*^+-. "
const text = imageToText(imageData, "@#&$%863!i1uazvno~;*^+-. ");
console.log(text);
Node.js
Method 1: with node-canvas
If you use it in Node.js without document, you need npm install canvas
.
yarn add canvas
node-canvas: need node-pre-gyp
Method 2: without native dependencies
yarn add jimp @canvas/image-data
import path from "path";
import jimp from "jimp";
import ImageData from "@canvas/image-data";
import { imageToText } from "char-dust";
const imagePath = path.resolve(__dirname, "./cat-of-the-rebellion.jpg");
jimp.read(imagePath).then((image) => {
// Magnify 5x
image.scale(5);
const imageData = new ImageData(
Uint8ClampedArray.from(image.bitmap.data),
image.bitmap.width,
image.bitmap.height
);
const text = imageToText(imageData);
console.log(text);
});
Functions
- Read Image
- Scale Image
- Convert to Char
- Console
- npm package
- Gif (may be you want google/gif-for-cli)
Todo
- 直方均衡化