Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hpp2334/elheif
A wasm heic image encoder and decoder library compiled from libheif, libde265 and kvazaar.
https://github.com/hpp2334/elheif
emscripten heic kvazaar libde265 libheif wasm
Last synced: 18 days ago
JSON representation
A wasm heic image encoder and decoder library compiled from libheif, libde265 and kvazaar.
- Host: GitHub
- URL: https://github.com/hpp2334/elheif
- Owner: hpp2334
- License: mit
- Created: 2024-06-11T17:34:58.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-06-14T17:01:06.000Z (6 months ago)
- Last Synced: 2024-11-27T09:14:30.868Z (27 days ago)
- Topics: emscripten, heic, kvazaar, libde265, libheif, wasm
- Language: C++
- Homepage:
- Size: 185 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# elheif
![Main](https://github.com/hpp2334/elheif/actions/workflows/main.yml/badge.svg)
[![npm version](https://badge.fury.io/js/elheif.svg)](https://badge.fury.io/js/elheif)A wasm heic image encoder and decoder library compiled from [libheif](https://github.com/strukturag/libheif), [libde265](https://github.com/strukturag/libde265) and kvazaar. The library is just a wrapper of `libheif` and compiled to WASM using Emscripten.
## API
```ts
interface DecodeImageResult {
err: string;
data: Array<{
width: number;
height: number;
/** RGBA8888 bitmap */
data: Uint8Array;
}>;
}interface EncodeImageResult {
err: string;
data: Uint8Array;
}/** Should be called and wait till promise fulfilled when using other APIs */
export function ensureInitialized(): Promise;/** Convert heic image to RGBA bitmaps */
export function jsDecodeImage(buf: Uint8Array): DecodeImageResult;/** Convert RGBA bitmap to heic image */
export function jsEncodeImage(
buf: Uint8Array,
width: number,
height: number
): EncodeImageResult;
```## Usage
```ts
it("decode", async () => {
await ensureInitialized();const buf = loadHeicImage();
const res = jsDecodeImage(buf);expect(res.err).eq("");
expect(res.data.length).eq(1);
expect(res.data[0].width).eq(10);
expect(res.data[0].height).eq(10);
});it("encode", async () => {
await ensureInitialized();const buf = loadHeicImage();
const bitmap = jsDecodeImage(buf).data[0];
const encoded = jsEncodeImage(bitmap.data, bitmap.width, bitmap.height);expect(encoded.err).eq("");
expect(encoded.data.length).eq(1288);
});
```## License
MIT license. Also note the license for `libheif`, `libde265` and `kvazaar`.