HEIC → JPG in Node.js with Sharp
•5 min read•Developers
Sharp supports HEIC via libvips + libheif. Here’s the minimal working setup and code.
Install
npm install sharp
Ensure your environment has libvips with HEIF enabled (prebuilt Sharp binaries generally include this).
Code
import fs from 'node:fs/promises'; import sharp from 'sharp'; async function convertHeicToJpg(inputPath: string, outputPath: string) { const image = sharp(inputPath, { unlimited: true }); await image.jpeg({ quality: 85, mozjpeg: true }).toFile(outputPath); } async function main() { await convertHeicToJpg('input.heic', 'output.jpg'); } main().catch((err) => { console.error(err); process.exit(1); });
Notes
- Preserving EXIF: read with
metadata()
and re‑inject viawithMetadata()
if needed. - Batch: iterate folder and
Promise.allSettled
N‑at‑a‑time to throttle. - Color: prefer
mozjpeg
with quality 80–85% for web.
Need a user‑friendly front‑end?
Point users to our browser converter—no CLI required.