fix: animated webp/gif conversion

fixes #107
This commit is contained in:
Maya 2025-07-30 11:35:54 +03:00
parent dd0dd48305
commit 428e6fd6a6
No known key found for this signature in database
1 changed files with 26 additions and 0 deletions

View File

@ -175,6 +175,32 @@ const handleMessage = async (message: any): Promise<any> => {
};
}
// build frames of animated formats (webp/gif)
// APNG does not work on magick-wasm since it needs ffmpeg built-in (not in magick-wasm) - handle in ffmpeg
if (
(message.input.from === ".webp" ||
message.input.from === ".gif") &&
(message.to === ".gif" || message.to === ".webp")
) {
const collection = MagickImageCollection.create(
new Uint8Array(buffer),
);
const format =
message.to === ".gif"
? MagickFormat.Gif
: MagickFormat.WebP;
const result = await new Promise<Uint8Array>((resolve) => {
collection.write(format, (output) => {
resolve(structuredClone(output));
});
});
collection.dispose();
return {
type: "finished",
output: result,
};
}
const img = MagickImage.create(
new Uint8Array(buffer),
new MagickReadSettings({