feat: add HEIC image support for iPhone uploads

This commit is contained in:
2025-12-18 12:01:31 +01:00
parent e339585e3a
commit d386bb9825
10 changed files with 31 additions and 201 deletions

View File

@@ -45,7 +45,28 @@ export default function CameraCapture({ onImageCaptured, onAnalysisComplete, onS
setMatchingBottle(null);
try {
const compressedBase64 = await compressImage(file);
let fileToProcess = file;
// HEIC / HEIF Check
const isHeic = file.type === 'image/heic' || file.type === 'image/heif' || file.name.toLowerCase().endsWith('.heic') || file.name.toLowerCase().endsWith('.heif');
if (isHeic) {
console.log('HEIC detected, converting...');
const heic2any = (await import('heic2any')).default;
const convertedBlob = await heic2any({
blob: file,
toType: 'image/jpeg',
quality: 0.8
});
// heic2any can return an array if the file contains multiple images
const blob = Array.isArray(convertedBlob) ? convertedBlob[0] : convertedBlob;
fileToProcess = new File([blob], file.name.replace(/\.(heic|heif)$/i, '.jpg'), {
type: 'image/jpeg'
});
}
const compressedBase64 = await compressImage(fileToProcess);
setPreviewUrl(compressedBase64);
if (onImageCaptured) {