
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
libheif-js
Advanced tools
An Emscripten build of
libheifdistributed as an npm module for Node.JS and the browser.
This module will respect the major and minor versions of the included libheif, with the patch version representing changes in this module itself. For the exact version of libheif, please see the install script.
npm install libheif-js
Starting with version 1.17, there are multiple variants of libheif that you can use:
const libheif = require('libheif-js');
wasm version available for use in NodeJS. This version will dymanically load the .wasm binary at runtime. While you may try to run this through a bundler, you are on your own for making it work.
const libheif = require('libheif-js/wasm');
wasm version that is pre-bundled for you, which includes the .wasm binary inside the .js bundle. You will have a much easier time using this in your browser bundle project.
const libheif = require('libheif-js/wasm-bundle');
If you'd like to include this module directly into an html page using a <script> tag, you have the following options:
Note: in the examples below, make sure to set the latest version when you use it. Always make sure to set a version, to make sure your website does not break unexpectedly when an update is released.
libheif global:
<script src="https://cdn.jsdelivr.net/npm/libheif-js@1.19.8/libheif/libheif.js"></script>
libheif global:
<script src="https://cdn.jsdelivr.net/npm/libheif-js@1.19.8/libheif-wasm/libheif-bundle.js"></script>
<script type="module">
import libheif from 'https://cdn.jsdelivr.net/npm/libheif-js@1.19.8/libheif-wasm/libheif-bundle.mjs';
</script>
In all cases, you can use this sample code to decode an image:
const file = fs.readFileSync('./temp/0002.heic');
const decoder = new libheif.HeifDecoder();
const data = decoder.decode(file);
// data in an array holding all images inside the heic file
const image = data[0];
const width = image.get_width();
const height = image.get_height();
In NodeJS, you might use this decoded data with other libraries, such as pngjs:
const { PNG } = require('pngjs');
const imageData = await new Promise((resolve, reject) => {
image.display({ data: new Uint8ClampedArray(width*height*4), width, height }, (displayData) => {
if (!displayData) {
return reject(new Error('HEIF processing error'));
}
resolve(displayData);
});
});
const png = new PNG({ width: imageData.width, height: imageData.height });
png.data = imageData.data;
const pngBuffer = PNG.sync.write(png);
In the browser, you might use this decoded data with canvas to display or convert the image:
const canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
const context = canvas.getContext('2d');
const imageData = context.createImageData(width, height);
await new Promise((resolve, reject) => {
image.display(imageData, (displayData) => {
if (!displayData) {
return reject(new Error('HEIF processing error'));
}
resolve();
});
});
context.putImageData(imageData, 0, 0);
This module contains the low-level libheif implementation. For more user-friendly functionality, check out these projects:
FAQs
Emscripten distribution of libheif for Node.JS and the browser
The npm package libheif-js receives a total of 478,062 weekly downloads. As such, libheif-js popularity was classified as popular.
We found that libheif-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.