# heic-convert

> Convert HEIC/HEIF images to JPEG and PNG

Latest version **2.1.0** (published 2023-11-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install heic-convert
pnpm add heic-convert
yarn add heic-convert
bun add heic-convert
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2023-11-30 |
| First published | 2020-01-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | separate (@types/heic-convert) |
| Module format | CommonJS |
| Node | >=12.0.0 |
| Dependencies | 3 |
| Unpacked size | 7.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 323 |
| Author | Kiril Vatev |
| Maintainers | kirilv |
| Keywords | heif, heic, convert, jpeg, jpg, png, image |

## Links

- npm: https://www.npmjs.com/package/heic-convert
- Repository: https://github.com/catdad-experiments/heic-convert
- Homepage: https://github.com/catdad-experiments/heic-convert#readme
- Issues: https://github.com/catdad-experiments/heic-convert/issues
- npm.io page: https://npm.io/package/heic-convert

## Dependencies (3)

- [pngjs](https://npm.io/package/pngjs.md) ^6.0.0
- [jpeg-js](https://npm.io/package/jpeg-js.md) ^0.4.4
- [heic-decode](https://npm.io/package/heic-decode.md) ^2.0.0

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 2.1.0 (latest) — 2023-11-30
- 2.0.0 — 2023-11-11
- 1.2.4 — 2020-12-23
- 1.2.3 — 2020-08-08
- 1.2.2 — 2020-02-05
- 1.2.1 — 2020-02-04
- 1.2.0 — 2020-02-03
- 1.1.0 — 2020-01-24
- 1.0.0 — 2020-01-18

## README

# heic-convert

> Convert HEIC/HEIF images to JPEG and PNG

[![ci][ci.svg]][ci.link]
[![npm-downloads][npm-downloads.svg]][npm.link]
[![npm-version][npm-version.svg]][npm.link]

[ci.svg]: https://github.com/catdad-experiments/heic-convert/actions/workflows/ci.yml/badge.svg
[ci.link]: https://github.com/catdad-experiments/heic-convert/actions/workflows/ci.yml
[npm-downloads.svg]: https://img.shields.io/npm/dm/heic-convert.svg
[npm.link]: https://www.npmjs.com/package/heic-convert
[npm-version.svg]: https://img.shields.io/npm/v/heic-convert.svg

## Install

```bash
npm install heic-convert
```

## Usage in NodeJS

Convert the main image in a HEIC to JPEG

```javascript
const { promisify } = require('util');
const fs = require('fs');
const convert = require('heic-convert');

(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 image in a HEIC to PNG

```javascript
const { promisify } = require('util');
const fs = require('fs');
const convert = require('heic-convert');

(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

```javascript
const { promisify } = require('util');
const fs = require('fs');
const convert = require('heic-convert');

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

  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 the `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._

## Usage in the browser

While the NodeJS version of `heic-convert` may be compiled for use in the browser with something like `webpack`, [not all build tools necessarily like to compile all modules well](https://github.com/catdad-experiments/heic-convert/issues/29). However, what further complicates things is that this module uses pure-javascript implementations of a jpeg and png encoder. But the browser has its own native encoders! Let's just use those instead of including a ton of extra code in your bundle.

When compiling a client-side project, use:

```javascript
const convert = require('heic-convert/browser');
```

This is currently only supported in the main thread. Support for workers may be added in the future, but if you need it sooner, please create an issue or even a PR!

## Related

* [heic-cli](https://github.com/catdad-experiments/heic-cli) - convert heic/heif images to jpeg or png from the command line
* [heic-decode](https://github.com/catdad-experiments/heic-decode) - decode heic images to raw image data
* [libheif-js](https://github.com/catdad-experiments/libheif-js) - libheif as a pure-javascript npm module

---
_Source: https://npm.io/package/heic-convert · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
