From a3a85dfff164e68a83b9c43ea32521be3797b37e Mon Sep 17 00:00:00 2001 From: Mathieu Fort Date: Wed, 27 May 2026 10:05:34 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20impl=C3=A9menter=20le=20convertisseur?= =?UTF-8?q?=20HEIC=20=E2=86=92=20JPEG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/heicConverter.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/js/heicConverter.js b/js/heicConverter.js index 1f5a563..4971c5a 100644 --- a/js/heicConverter.js +++ b/js/heicConverter.js @@ -1,3 +1,29 @@ +/** + * Convertit un fichier HEIC/HEIF en Blob JPEG. + * @param {File} file + * @returns {Promise} + * @throws {TypeError} si l'entrée n'est pas un fichier HEIC/HEIF + * @throws {Error} si la conversion échoue + */ export async function convertHeicToJpeg(file) { - throw new Error('Not implemented'); + if (!(file instanceof File)) { + throw new TypeError("L'entrée doit être un objet File"); + } + // Certains iPhone envoient un type MIME vide pour les HEIC — on l'autorise + const type = file.type.toLowerCase(); + if (type !== '' && !['image/heic', 'image/heif'].includes(type)) { + throw new TypeError(`Format attendu : HEIC/HEIF. Reçu : ${file.type}`); + } + + const result = await heic2any({ + blob: file, + toType: 'image/jpeg', + quality: 0.92, + }); + + const blob = Array.isArray(result) ? result[0] : result; + if (!(blob instanceof Blob)) { + throw new Error("heic2any n'a pas retourné un Blob"); + } + return blob; }