Native node bindings for libheif - a HEIC/HEIF image decoder.
There are JavaScript-only builds of libheif
- like libheif-js or
heic2any.
The difference is:
node-libheif
is about 3 x faster (1100 ms instead of 3300 ms for a 3024 x 4032 image).node-libheif
has native parts, sonode-libheif
will only work in a nodejs environment - it won't run in a browser.
Install node-libheif
:
npm i --save node-libheif
Decode a HEIC/HEIF file:
import { promises as fs } from 'fs'
import { decodeHeifFile } from 'node-libheif'
const imageBuffer = await fs.readFile('path/to/myimage.heic')
const decodedImage = await decodeHeifBuffer(imageBuffer)
decodedImage.width // Width in px
decodedImage.height // Height in px
decodedImage.data // Buffer with RGB data (8 bit per channel). size in bytes = 3 * width * height
Clone repo:
git clone https://github.com/picturama/node-libheif.git
cd node-libheif
git submodule update --init
Build:
npm i
Run test (after adjusting testImagePath
in test.ts
):
node test.js