0.0.1 • Published 4 years ago

smartcrop-wasm v0.0.1

Weekly downloads
5
License
-
Repository
github
Last release
4 years ago

smartcrop-wasm

npm version install size

WebAssembly implementation of smartcrop.js.

Install

# npm
$ npm install smartcrop-wasm

# or yarn
$ yarn add smartcrop-wasm

Usage

import * as smartcrop from 'smartcrop-wasm';

const image = await fetch(img.src)
  .then((res) => res.arrayBuffer())
  .then((res) => new Uint8Array(res));

const result = smartcrop.crop(image, 100, 100);
// => [ 0, 25, 200, 200 ]

API

crop(image, width, height)

Find the best crop for image.

args

image: Uint8Array

The image data converted Uint8Array.

width: number

Crop width.

height: number

Crop height.

return: number, number, number, number

Return x, y, width, height result.

Development

# build for wasm
$ wasm-pack build

# npm package files
$ tree pkg
pkg/
├── package.json
├── README.md
├── smartcrop_wasm_bg.d.ts
├── smartcrop_wasm_bg.js
├── smartcrop_wasm_bg.wasm
├── smartcrop_wasm.d.ts
└── smartcrop_wasm.js