Socket
Book a DemoInstallSign in
Socket

heic-to

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

heic-to

Converting HEIF/HEIF image formats to PNG/JPEG in the browser

1.2.2
latest
Source
npmnpm
Version published
Weekly downloads
59K
2.7%
Maintainers
1
Weekly downloads
 
Created
Source

heic-to

Convert HEIC/HEIF images to JPEG, PNG in browser using Javascript.

Inspired by heic2any and libheif-web. The purpose of heic-to is to continuously follow up on releases of libheif to be able to preview HEIC/HEIF images in browser.

Currently, heic-to is using libheif 1.20.2 under the hood.

Releaselibheif
1.2.21.20.2
1.2.11.20.1
1.2.01.20.0
1.1.141.19.8
1.1.141.19.8
1.1.131.19.8
1.1.121.19.7
1.1.111.19.7
1.1.101.19.7
1.1.91.19.7
1.1.81.19.7
1.1.71.19.6
1.1.61.19.5
1.1.51.19.5
1.1.41.19.4
1.1.31.19.3
1.1.21.19.2
1.1.11.19.1
1.1.01.19.0
1.0.31.18.2
1.0.21.18.2
1.0.11.18.2
1.0.01.18.1

Demo

Try the 🌟 live demo.

Usage

Check whether the image is HEIC or not

import { isHeic } from "heic-to"

const file = field.files[0]
await isHeic(file)

Convert HEIC to JPEG/PNG

import { heicTo } from "heic-to"

const file = field.files[0]

const jpeg = await heicTo({
  blob: file,
  type: "image/jpeg",
  quality: 0.5
})

const png = await heicTo({
  blob: file,
  type: "image/png",
  quality: 0.5
})

Cotent Security Policy

When meets CSP issue like this:

Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive

Fix it by using csp/heic-to

- import { heicTo } from "heic-to"
+ import { heicTo } from "heic-to/csp"

Access global variable with IIFE build

If you would like to access heic-to with pure JavaScript without package builder like with CDN.

<script src="https://cdn.jsdelivr.net/npm/heic-to@1.2.2/dist/iife/heic-to.js"></script>
<script>
  /*...*/
  if (await HeicTo.isHeic(file)) {
    const jpeg = await HeicTo({
      blob: file,
      type: "image/jpeg",
      quality: 0.5
    })
    /*...*/
  }
  /*...*/
</script>

Call heic-to in web worker

If you want to call heicTo in web workers:

- import { heicTo } from "heic-to"
+ import { heicTo } from "heic-to/next"

Development guide

How to fast test your changes on local?

yarn s

This will open http://127.0.0.1:8080/example/ for easy testing.

How to build libheif.js from libheif on Mac

brew install cmake make pkg-config x265 libde265 libjpeg libtool
brew install emscripten

git clone git@github.com:strukturag/libheif.git

Did below changes from build-emscripten.sh

# EXPORTED_FUNCTIONS=$($EMSDK/upstream/bin/llvm-nm $LIBHEIFA --format=just-symbols | grep "^heif_\|^de265_\|^aom_" | grep "[^:]$" | sed 's/^/_/' | paste -sd "," -)
EXPORTED_FUNCTIONS=$(/opt/homebrew/opt/llvm/bin/llvm-nm $LIBHEIFA --format=just-symbols | grep "^heif_\|^de265_\|^aom_" | grep "[^:]$" | sed 's/^/_/' | paste -sd "," -)

Start building

cd libheif
mkdir buildjs
cd buildjs
USE_WASM=0 ../build-emscripten.sh ..

# Or build without unsafe-eval
USE_UNSAFE_EVAL=0 USE_WASM=0 ../build-emscripten.sh ..

Keywords

heic

FAQs

Package last updated on 13 Aug 2025

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.