Skip to content

armgit / VERT

Public Imported from GitHub
0

The next-generation file converter. Open source, fully local* and free forever.

fix: animated image conversion

JovannMCbc91d7d637ac
diff --git a/src/lib/workers/vips.ts b/src/lib/workers/vips.ts
index 8424cfc..d0d8e8c 100644
--- a/src/lib/workers/vips.ts
+++ b/src/lib/workers/vips.ts
@@ -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 {