heic-converter
v1.0.0
Published
Convert HEIC images to PNG/JPEG entirely in the browser using libheif-js
Maintainers
Readme
heic-converter
Convert HEIC images to PNG/JPEG entirely in the browser using libheif-js.
Features
- Zero backend dependencies - Runs entirely in the browser using WebAssembly
- Simple API - Clear function names and straightforward usage
- TypeScript support - Full type definitions included
- Multi-image support - Handle HEIC files with multiple images (bursts)
- Privacy-focused - All processing happens client-side
Installation
npm install heic-converterQuick Start
import { heicToPng, heicToJpeg } from 'heic-converter';
// Convert HEIC to PNG
const pngBlob = await heicToPng(heicFile);
// Convert HEIC to JPEG with quality setting
const jpegBlob = await heicToJpeg(heicFile, { quality: 0.8 });Usage
Convert to PNG
import { heicToPng } from 'heic-converter';
const pngBlob = await heicToPng(heicFile);
const url = URL.createObjectURL(pngBlob);Convert to JPEG
import { heicToJpeg } from 'heic-converter';
const jpegBlob = await heicToJpeg(heicFile, { quality: 0.92 });Handle Multi-Image HEIC Files
HEIC files can contain multiple images (e.g., burst photos):
import { heicToPng } from 'heic-converter';
const pngBlobs = await heicToPng(heicFile, { multiple: true });
pngBlobs.forEach((blob, index) => {
console.log(`Image ${index + 1}:`, blob);
});Check if File is HEIC
import { isHeic } from 'heic-converter';
if (await isHeic(file)) {
const pngBlob = await heicToPng(file);
}Advanced Usage
import { convert } from 'heic-converter';
const blob = await convert(heicFile, {
format: 'jpeg',
quality: 0.95,
multiple: false
});API Reference
heicToPng(blob, options?)
Converts a HEIC image to PNG format.
| Parameter | Type | Description |
|-----------|------|-------------|
| blob | Blob | The HEIC image to convert |
| options.multiple | boolean | Extract all images from multi-image HEIC files (default: false) |
Returns: Promise<Blob> or Promise<Blob[]> if multiple is true
heicToJpeg(blob, options?)
Converts a HEIC image to JPEG format.
| Parameter | Type | Description |
|-----------|------|-------------|
| blob | Blob | The HEIC image to convert |
| options.quality | number | JPEG quality between 0 and 1 (default: 0.92) |
| options.multiple | boolean | Extract all images from multi-image HEIC files (default: false) |
Returns: Promise<Blob> or Promise<Blob[]> if multiple is true
convert(blob, options)
Generic conversion function for advanced use cases.
| Parameter | Type | Description |
|-----------|------|-------------|
| blob | Blob | The HEIC image to convert |
| options.format | 'png' \| 'jpeg' | Output format (required) |
| options.quality | number | JPEG quality between 0 and 1 (default: 0.92, ignored for PNG) |
| options.multiple | boolean | Extract all images from multi-image HEIC files (default: false) |
Returns: Promise<Blob> or Promise<Blob[]> if multiple is true
isHeic(blob)
Checks if a file is a HEIC/HEIF image by examining its file signature.
| Parameter | Type | Description |
|-----------|------|-------------|
| blob | Blob | The file to check |
Returns: Promise<boolean> - true if the file is HEIC/HEIF
TypeScript
Full TypeScript support with included type definitions:
import type { ConvertOptions, ConvertOptionsWithFormat } from 'heic-converter';
interface ConvertOptions {
quality?: number; // 0-1 for JPEG (default: 0.92)
multiple?: boolean; // Handle multi-image HEIC files (default: false)
}
interface ConvertOptionsWithFormat extends ConvertOptions {
format: 'png' | 'jpeg';
}Browser Support
Requires a modern browser with:
- WebAssembly support
- Canvas API
- ES2020+ features
Supported browsers:
- Chrome/Edge 87+
- Firefox 89+
- Safari 15+
How It Works
- Uses libheif-js (WebAssembly) to decode HEIC to raw image data
- Renders the decoded data to an HTML Canvas
- Exports the canvas as PNG or JPEG Blob
- All processing happens entirely in the browser - no server uploads
License
MIT
Contributing
Contributions are welcome! Please open an issue or pull request on GitHub.
Credits
Built with libheif-js, the WebAssembly build of libheif.
