fix: animated image conversion

my bad i broke static images

better code by checking if it has frames before adding the n parameter
This commit is contained in:
JovannMC 2025-02-26 20:01:59 +03:00
parent c9518d2967
commit bc91d7d637
No known key found for this signature in database
1 changed files with 8 additions and 4 deletions

View File

@ -18,10 +18,14 @@ const handleMessage = async (message: any): Promise<any> => {
switch (message.type) {
case "convert": {
if (!message.to.startsWith(".")) message.to = `.${message.to}`;
const image = vips.Image.newFromBuffer(
await message.input.file.arrayBuffer(),
`${message.to === ".gif" || message.to === ".webp" ? "[n=-1]" : ""}`,
);
const buffer = await message.input.file.arrayBuffer();
let image = vips.Image.newFromBuffer(buffer, "");
// check if animated image & keep it animated when converting
if (image.getTypeof("n-pages") > 0) {
image = vips.Image.newFromBuffer(buffer, "[n=-1]");
}
const output = image.writeToBuffer(message.to);
image.delete();
return {