heic-detect-converter
v0.0.8
Published
Automatically detect real HEIC images and convert to displayable JPG or PNG in the browser
Maintainers
Readme
heic-detect-converter
一个在 在浏览器中自动检测文件真实 HEIC 类型并转换为可显示的 JPG 或 PNG 的轻量工具。
用于解决 file.type 被错误标记为 image/png或者 image/jpeg 的情况
A lightweight utility that automatically detects real HEIC files in the browser and converts them to displayable JPG or PNG, even when the file.type is incorrectly labeled as image/png or image/jpeg.
✨ 功能特点 (Features)
- ✅ 自动识别 HEIC 图片(即使
file.type被错误标记为image/png) - ✅ 在浏览器端完成 HEIC → JPG/PNG 转换,无需后端处理
- ✅ 输出格式自动判断:
- 带透明度 → PNG
- 不带透明度 → JPG
- ✅ 支持 TypeScript 类型提示
- ✅ 非图片会抛出异常,避免错误操作
- ✅ Automatically detects HEIC images (even when reported as
image/png) - ✅ Converts HEIC → JPG/PNG directly in the browser — no backend required
- ✅ Smart format output:
- Images with transparency → PNG
- Images without transparency → JPG
- ✅ Full TypeScript type support
- ✅ Throws errors for non-image files to prevent misuse
📦 安装方式 (Installation)
npm install heic-detect-converter
# 或 or
yarn add heic-detect-converter
# 或 or
pnpm add heic-detect-converter🚀 使用示例 (Usage Example)
ES Module
import convertHeicToImage from 'heic-detect-converter';
const handleFile = async (file: File) => {
try {
const output = await convertHeicToImage(file);
console.log(output); // Blob
} catch (err) {
console.error(err);
alert('文件不是图片或无法转换');
}
};CommonJS
const convertHeicToImage = require('heic-detect-converter');
async function handleFile(file) {
try {
const output = await convertHeicToImage(file);
console.log(output); // Blob
} catch (err) {
console.error(err);
alert('文件不是图片或无法转换');
}
}