https://github.com/seriousbug/libheif-node-dy
Dynamically linked libheif for nodejs. Native HEIC/HEIF image decoding and information using dynamically linked libheif.
https://github.com/seriousbug/libheif-node-dy
heic heic-convert heic-converter heic-decode heic-to-jpeg heic-to-jpg heic-to-png heif heif-converter heif-decode node nodejs
Last synced: about 1 month ago
JSON representation
Dynamically linked libheif for nodejs. Native HEIC/HEIF image decoding and information using dynamically linked libheif.
- Host: GitHub
- URL: https://github.com/seriousbug/libheif-node-dy
- Owner: SeriousBug
- License: mit
- Created: 2023-04-15T17:23:18.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-16T20:52:55.000Z (about 3 years ago)
- Last Synced: 2025-10-12T19:44:10.800Z (9 months ago)
- Topics: heic, heic-convert, heic-converter, heic-decode, heic-to-jpeg, heic-to-jpg, heic-to-png, heif, heif-converter, heif-decode, node, nodejs
- Language: Jupyter Notebook
- Homepage:
- Size: 149 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# libheif-node-dy [](https://www.npmjs.com/package/libheif-node-dy) [](https://github.com/SeriousBug/libheif-node-dy/blob/main/LICENSE)
Native HEIC/HEIF image decoding and information, using dynamically linked [libheif](https://github.com/strukturag/libheif). Supports converting HEIC to JPEG, PNG, and other formats when combined with [Sharp](https://sharp.pixelplumbing.com/).
This package dynamically links against libheif. You must have libheif and its
headers installed yourself. It is widely available on most platforms:
- Debian, Ubuntu: `libheif1 libheif-dev`
- ArchLinux, EndeavourOS: `libheif`
- Alpine Linux: `libheif-dev`
- MacOS (Homebrew): `libheif`
Once you have `libheif` installed, you can install this package with `npm install libheif-node-dy`.
## Usage
```js
const fs = require('fs');
const { decode, getInfo } = require('libheif-node-dy');
// Or, import { decode, getInfo } from 'libheif-node-dy';
// Or any other way to get your image into a Buffer
const image = fs.readFileSync('path-to.heic');
// There is more information available! Check the type definitions.
const { width, height } = getInfo(image);
const decodedImage = decode(image);
// To convert it into JPEG or PNG, use it with sharp:
const sharp = require('sharp');
const newImage = sharp(decodedImage, {
raw: {
height,
width,
channels: 4,
},
});
newImage.jpeg().toFile("image.jpg");
// Or .toBuffer() to get a buffer to use in something else
```
You can also look at the [benchmark/convert.js](benchmark/convert.js) file,
which is an example CLI program for converting HEIC files to JPEGs.
## Performance
`libheif-node-dy` is around 3 to 5 times faster than `heic-decode` in decoding images.

## Licensing
This package is licensed under MIT. `libheif` is licensed under LGPL, which
grants an exception for dynamic linking. This package dynamically links against
libheif, which should satisfy that requirement. This means you can use this
package without licensing your software under GPL, so long as you don't bundle
your application in a way that restricts users from being able to replace
libheif.
Note that other packages like
[libheif-js](https://www.npmjs.com/package/libheif-js), and thus its
dependencies like [heic-decode](https://www.npmjs.com/package/heic-decode) may
require you to license your software under GPL if you bundle them within your
application in a way that users could not replace the library.
Bundlers like rollup, webpack, and others that bundle all code into one or a few
files very likely will violate the LGPL exception, and will therefore require
you to distribute your application under GPL, if you do distribute your
application.
This is not legal advice, and I'm not a lawyer. Contact a lawyer if you have
questions on how these licenses apply to your application.