Socket
Socket
Sign inDemoInstall

heic-convert

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

heic-convert

Convert HEIC/HEIF images to JPEG and PNG


Version published
Weekly downloads
60K
increased by7.79%
Maintainers
1
Weekly downloads
 
Created
Source

heic-convert

Convert HEIC/HEIF images to JPEG and PNG

travis npm-downloads npm-version

Install

npm install heic-decode

Usage

Convert the main image in a HEIC to JPEG

const { promisify } = require('util');
const fs = require('fs');

(async () => {
  const inputBuffer = await promisify(fs.readFile)('/path/to/my/image.heic');
  const outputBuffer = await convert({
    buffer: inputBuffer, // the HEIC file buffer
    format: 'JPEG',      // output format
    quality: 1           // the jpeg compression quality, between 0 and 1
  });

  await promisify(fs.writeFile)('./result.jpg', outputBuffer);
})();

Convert the main imgae in a HEIC to PNG

const { promisify } = require('util');
const fs = require('fs');

(async () => {
  const inputBuffer = await promisify(fs.readFile)('/path/to/my/image.heic');
  const outputBuffer = await convert({
    buffer: inputBuffer, // the HEIC file buffer
    format: 'PNG'        // output format
  });

  await promisify(fs.writeFile)('./result.png', outputBuffer);
})();

Convert all images in a HEIC

const { promisify } = require('util');
const fs = require('fs');

(async () => {
  const inputBuffer = await promisify(fs.readFile)('/path/to/my/image.heic');
  const images = await convert({ inputBuffer, format: 'JPEG' });

  for (let idx in images) {
    const image = images[idx];
    const outputBuffer = await image.convert();
    await promisify(fs.writeFile)(`./result-${idx}.jpg`, outputBuffer);
  }
})();

The work to convert an image is done when calling image.convert(), so if you only need one of the images in a multi-image file, you can convert just that one from tha images array and skip doing any work for the remaining images.

Note that while the converter returns a Promise and is overall asynchronous, a lot of work is still done synchronously, so you should consider using a worker thread in order to not block the main thread in highly concurrent production environments.

  • heic-cli - convert heic/heif images to jpeg or png from the command line
  • heic-decode - decode heic images to raw image data
  • libheif-js - libheif as a pure-javascript npm module

Keywords

FAQs

Package last updated on 03 Feb 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc