项目作者: YunYouJun

项目描述 :
📝 Convert image to char.
高级语言: TypeScript
项目地址: git://github.com/YunYouJun/char-dust.git
创建时间: 2018-07-19T12:15:11Z
项目社区:https://github.com/YunYouJun/char-dust

开源协议:MIT License

下载


char-dust

GitHub Pages
npm

Convert image to char.

示例 | Demo

由来 | Why char-dust?


夹心酱
xiao-yun char
夹心酱
jashin char

Usage

  1. yarn add char-dust
  2. # npm install char-dust

Browser

  1. <img id="demo-image" src="xxx" />
  1. import { imageToText, getImageData } from "char-dust";
  2. const imageElement = document.getElementById("demo-image");
  3. const imageData = getImageData(imageElement);
  4. // const text = imageToText(imageData);
  5. // default is "@#&$%863!i1uazvno~;*^+-. "
  6. const text = imageToText(imageData, "@#&$%863!i1uazvno~;*^+-. ");
  7. console.log(text);

Node.js

Method 1: with node-canvas

If you use it in Node.js without document, you need npm install canvas.

  1. yarn add canvas

node-canvas: need node-pre-gyp

Method 2: without native dependencies

  1. yarn add jimp @canvas/image-data
  1. import path from "path";
  2. import jimp from "jimp";
  3. import ImageData from "@canvas/image-data";
  4. import { imageToText } from "char-dust";
  5. const imagePath = path.resolve(__dirname, "./cat-of-the-rebellion.jpg");
  6. jimp.read(imagePath).then((image) => {
  7. // Magnify 5x
  8. image.scale(5);
  9. const imageData = new ImageData(
  10. Uint8ClampedArray.from(image.bitmap.data),
  11. image.bitmap.width,
  12. image.bitmap.height
  13. );
  14. const text = imageToText(imageData);
  15. console.log(text);
  16. });

Functions

  • Read Image
  • Scale Image
  • Convert to Char
  • Console
  • npm package
  • Gif (may be you want google/gif-for-cli)

Todo

  • 直方均衡化

Ref