Nifty Pun Master

    char-dust
    TypeScript icon, indicating that this package has built-in type declarations

    0.1.0 • Public • Published

    char-dust

    GitHub Pages npm

    Convert image to char.

    示例 | Demo

    由来 | Why char-dust?

    夹心酱 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

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

    Todo

    • 直方均衡化

    Ref

    Keywords

    Install

    npm i char-dust

    DownloadsWeekly Downloads

    1

    Version

    0.1.0

    License

    MIT

    Unpacked Size

    10.8 kB

    Total Files

    6

    Last publish

    Collaborators

    • yunyoujun