From f03bc2171f705a7321e2324c825ce539274176d9 Mon Sep 17 00:00:00 2001 From: Augusto Blomer Date: Sun, 2 Feb 2025 22:43:02 -0500 Subject: [PATCH] Fixed image to image conversion --- src/App.tsx | 1 + src/utils/mediaConverter.ts | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 4fafc28..f9d8096 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -365,6 +365,7 @@ export default function App() { )} + 0.9.1 beta diff --git a/src/utils/mediaConverter.ts b/src/utils/mediaConverter.ts index c0dcefb..a3082f0 100644 --- a/src/utils/mediaConverter.ts +++ b/src/utils/mediaConverter.ts @@ -121,8 +121,28 @@ async function convertWithImageMagick( onProgress(50); // halfway: reading complete - // Convert to the specified format - const format = MagickFormat[targetFormat.toUpperCase() as keyof typeof MagickFormat]; + // Map common format names to MagickFormat enum values + const formatMap: Record = { + 'png': 'Png', + 'jpg': 'Jpg', + 'jpeg': 'Jpg', + 'webp': 'WebP', + 'gif': 'Gif', + 'bmp': 'Bmp', + 'tiff': 'Tiff' + }; + + const formatKey = formatMap[targetFormat.toLowerCase()]; + if (!formatKey) { + reject(new Error(`Unsupported target format: ${targetFormat}`)); + return; + } + + const format = MagickFormat[formatKey]; + onLog(`Converting to format: ${formatKey}`); + + // Set the format and convert + image.format = format; image.write(format, (data: Uint8Array) => { if (isCancelled) { reject(new Error('Conversion cancelled'));