Skip to content

Commit

Permalink
Fixed image to image conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
ablomer committed Feb 3, 2025
1 parent 6213b16 commit f03bc21
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ export default function App() {
)}
</Stack>
</Paper>
<Text c="dimmed" size="xs" ta="center" ff="monospace" fw={500}>0.9.1 beta</Text>
</Stack>
</Container>
</MantineProvider>
Expand Down
24 changes: 22 additions & 2 deletions src/utils/mediaConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, keyof typeof MagickFormat> = {
'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'));
Expand Down

0 comments on commit f03bc21

Please sign in to comment.