1.0.35 • Published 3 years ago

@dannadori/asciiart-worker-js v1.0.35

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

This is webworker module for AsciiArt.

asciiart

image

Install

$ npm install \@dannadori/asciiart-worker-js

API

generateAsciiArtDefaultConfig: () => AsciiConfig;
generateDefaultAsciiArtParams: () => AsciiOperationParams;

AsciiArtWorkerManager
init: (config: AsciiConfig | null) => Promise<unknown>;
predict(targetCanvas: HTMLCanvasElement, params: AsciiOperationParams): Promise<HTMLCanvasElement>;

Configuration and Parameter

export interface AsciiConfig{
    browserType         : BrowserType
    processOnLocal      : boolean
}


export interface AsciiOperationParams{
    type: AsciiFunctionType
    processWidth        : number
    processHeight       : number
    asciiStr            : string
    fontSize            : number
}

export enum AsciiFunctionType{
    AsciiArt
}

Step by step

Create environment and install package

$ npx create-react-app demo --template typescript
$ cd demo/
$ npm install
$ npm install @dannadori/asciiart-worker-js

Add source image to public.

In this time, the name is "srcImage.jpg"

Edit src/App.tsx

Sample code is here.

import React from 'react';
import './App.css';
import { AsciiArtWorkerManager, generateAsciiArtDefaultConfig, generateDefaultAsciiArtParams } from '@dannadori/asciiart-worker-js'

class App extends React.Component{

  manager = new AsciiArtWorkerManager()
  config = generateAsciiArtDefaultConfig()
  params = generateDefaultAsciiArtParams()

  srcCanvas = document.createElement("canvas")
  dstCanvas = document.createElement("canvas")

  componentDidMount = () =>{
    document.getRootNode().lastChild!.appendChild(this.srcCanvas)
    document.getRootNode().lastChild!.appendChild(this.dstCanvas)
    const srcImage = document.createElement("img")
    srcImage.onload = () =>{
      this.manager.init(this.config).then(()=>{
        this.srcCanvas.getContext("2d")!.drawImage(
          srcImage, 0, 0, this.srcCanvas.width, this.dstCanvas.height)
        return this.manager.predict(this.srcCanvas, this.params)
      }).then((res)=>{
        console.log(res)
        this.dstCanvas.getContext("2d")!.drawImage(res, 0, 0, this.dstCanvas.width, this.dstCanvas.height)
      })
    }
    srcImage.src = "./srcImage.jpg"
  }

  render = ()=>{
    return (
      <div className="App">
      </div>
    );
  }
}

export default App;

build and start

$ npm run start
1.0.29

3 years ago

1.0.28

3 years ago

1.0.33

3 years ago

1.0.32

3 years ago

1.0.31

3 years ago

1.0.30

3 years ago

1.0.35

3 years ago

1.0.34

3 years ago

1.0.27

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.23

4 years ago

1.0.20

4 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago