fix: correct ImageMagick write API to produce valid WebP data
The previous implementation was producing invalid image data with wrong magic bytes (d0 e5 67 00 instead of 52 49 46 46 for WebP). Root cause: Incorrect usage of ImageMagick write API. Changes: - Set image.format BEFORE writing (tells ImageMagick the output format) - Simplified write() call to: image.write((data) => data) - This returns the correctly formatted image data The proper pattern is: 1. Set image.format = outputFormatEnum 2. Apply transformations (quality, resize) 3. Call image.write() which returns the encoded data This should now produce valid WebP files with correct RIFF header (52 49 46 46) and allow the preview to display properly. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user