0.1.13 • Published 2 years ago

libavif-wasm v0.1.13

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

WIP

fork https://github.com/saschazar21/webassembly

  • support ts
  • support browser and node
  • support more encode/decode options
  • not support encode from file, convert file to pixels is very complex, so you should use other 3rd lib.

install

npm i libavif-wasm

usage

import { init, decode, encode, destroy, AvifPixelFormat } from "../dist";

await init();

const file = readFileSync(join(root, "img", "fixture-yuv420-8bit.avif"));
const image = await decode(file, { alphaPresent: true });
const { data, width, height, channel } = image;
expect(data.length).toEqual(width * height * channel);
import { checkImage } from 'check-image-type';

const encodeFile = await encode(data, width, height, channel, {
      speed: 3,
      minQuantizer: 40,
      maxQuantizer: 50,
      minQuantizerAlpha: 20,
      maxQuantizerAlpha: 30,
      avifPixelFormat: AvifPixelFormat.AVIF_PIXEL_FORMAT_YUV444,
});
const imageType = checkImage(encodeFile);
expect(imageType?.ext === "avif");

destroy();

API

init

destroy

encode

decode