Convert image to char.
yarn add char-dust
# npm install char-dust
<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);
If you use it in Node.js without document, you need npm install canvas
.
yarn add canvas
node-canvas: need node-pre-gyp
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);
});
- Read Image
- Scale Image
- Convert to Char
- Console
- npm package
- Gif
- 直方均衡化