npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@myunisoft/heif-converter

v0.2.3

Published

Bindings for the libheif C API to convert an image in Node.js

Downloads

515

Readme

🥦 HEIF-Converter

This module uses the C APIs libheif to bind it in Node.js using N-API.

Engine

Node

  • Node.js 18.x

Prebuilt binaries

  • MacOS x64 (>= 12)
  • Windows x64/x86
  • Linux x64 (glibc >= 2.28, musl >= 1.2.4)

⭐ Introduction

The libheif library is a software library used to read and write HEIF (High Efficiency Image Format) files.

HEIF is a file format for images and image sequences (like photos and videos) that offers superior compression compared to traditional formats like JPEG and PNG while maintaining high image quality.

For more information about the librarie used in this project, you can visit the following links:

❤️ Motivations

We created this module because, to date, we have not yet found a package that uses Node.js bindings for the libheif C library. Libraries like heic-convert, and others are very interesting but do not allow full utilization of the performance and speed of the C library.

Moreover, this project allows you to use asynchronous methods that will run in an AsyncWorker, which will prevent blocking the event loop of your application.

💥 Prerequisites

Before installing heif-converter, make sure you have the following tools installed on your machine:

🎈 Conversion

The heif-converter package facilitates the conversion of HEIF (High Efficiency Image File Format) images to other formats. However, it's important to note that this package specifically handles static images and does not support animated images. Additionally, metadata and auxiliary images within the HEIF file are not currently supported by the converter. You're welcome to contribute by suggesting improvements or enhancements to its functionality 😃.

Developer

If you wish to contribute or build libheif from source, you can visit this link.

🦴 Installation

npm install @myunisoft/heif-converter

🚀 API

The version method is used to obtain the version of libheif.

function version(): string;
import lib from "../index.js";

console.log(lib.version());
// 1.17.6

The toJpeg method converts the primary image of a HEIC file to jpg.

Converts only the primary image of the HEIC file.

interface JpegOptions {
  // 0 to 100.
  quality?: number;
}

function toJpeg(
  input: string | Buffer | Readable, 
  options?: JpegOptions
): Promise<Buffer>;
// Import Node.js Dependencies
import path from "node:path";

// Import Internal Dependencies
import lib from "../index.js";

const filePath = path.join(__dirname, "image.heic")
const jpegBuffer = await lib.toJpeg(filePath, { quality: 20 });

The value of the quality option is from 0 to 100. Default 75.

The toPng method converts the primary image of a HEIC file to png.

Converts only the primary image of the HEIC file.

function toPng(input: string | Buffer | Readable): Promise<Buffer>;
// Import Node.js Dependencies
import path from "node:path";

// Import Internal Dependencies
import lib from "../index.js";

const filePath = path.join(__dirname, "image.heic")
const pngBuffer = await lib.toPng(filePath, { compression: 5 });

The value of the compression option is from 1 to 9. Default 1.

The extract method allows you to obtain a list of images contained in a HEIC file. Each extracted image has two methods, toJpeg and toPng, which allow you to convert the image to JPEG or PNG format, respectively, as documented above.

interface JpegOptions {
  quality?: number;
}

interface PngOptions {
  compression?: number;
}

interface ExtractedImage {
  toJpeg: (opts?: JpegOptions) => Promise<Buffer>;
  toPng: (opts?: PngOptions) => Promise<Buffer>;
}

function extract(input: string | Buffer | Readable): Promise<ExtractedImage[]>;
// Import Node.js Dependencies
import path from "node:path";

// Import Internal Dependencies
import lib from "../index.js";

const filePath = path.join(__dirname, "image.heic")
const images = await lib.extract(filePath);
for (image of images) {
  const jpegBuffer = await image.toJpeg({ quality: 50 });
}

📢 Benchmark

The benchmark is accessible in the ./benchmark folder. You can run the following commands.

$ node ./benchmark/bench.js 1
# OR
$ node ./benchmark/bench.js 2
# OR
$ node ./benchmark/bench.js 3

This benchmark was conducted on a mid-range machine.

HEIC file containing an image of 3992*2992.

HEIC file containing an image of 2400*1600.

HEIC file containing an image of 640*426.