feat: add HEIC image support for iPhone uploads
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user