YunYouJun / char-dust

📝 Convert image to char. 在线图片转字符画~

Home Page:https://yunyoujun.github.io/char-dust/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

char-dust

GitHub Pages npm

Convert image to char.

示例 | Demo

由来 | Why char-dust?

夹心酱 xiao-yun char 夹心酱 jashin 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

  • 直方均衡化

Ref

About

📝 Convert image to char. 在线图片转字符画~

https://yunyoujun.github.io/char-dust/

License:MIT License


Languages

Language:TypeScript 100.0%