diff --git a/lib/converters/imagemagickService.ts b/lib/converters/imagemagickService.ts index 1d12160..5bb3735 100644 --- a/lib/converters/imagemagickService.ts +++ b/lib/converters/imagemagickService.ts @@ -39,6 +39,9 @@ export async function convertWithImageMagick( let result: Uint8Array | undefined; await ImageMagick.read(inputData, (image) => { + // Set the output format first + image.format = outputFormatEnum; + // Apply quality setting if specified if (options.imageQuality !== undefined) { image.quality = options.imageQuality; @@ -65,10 +68,8 @@ export async function convertWithImageMagick( if (onProgress) onProgress(70); - // Write to output format - image.write(outputFormatEnum, (data) => { - result = data; - }); + // Write the image data + result = image.write((data) => data); if (onProgress) onProgress(90); });