added ffmpeg

This commit is contained in:
C4illin 2024-05-21 15:34:38 +02:00
parent e55b8abaa0
commit 4aeeaa5060
8 changed files with 911 additions and 113 deletions

View file

@ -1,4 +1,5 @@
import sharp from "sharp";
import type { FormatEnum } from "sharp";
// declare possible conversions
export const properties = {
@ -11,11 +12,18 @@ export const properties = {
type: "number",
default: 1,
},
}
}
}
},
},
};
export async function convert(filePath: string, fileType: string, convertTo: string, targetPath: string, options?: any) {
export async function convert(
filePath: string,
fileType: string,
convertTo: keyof FormatEnum,
targetPath: string,
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
options?: any,
) {
if (fileType === "svg") {
const scale = options.scale || 1;
const metadata = await sharp(filePath).metadata();
@ -24,14 +32,14 @@ export async function convert(filePath: string, fileType: string, convertTo: str
throw new Error("Could not get metadata from image");
}
const newWidth = Math.round(metadata.width * scale)
const newHeight = Math.round(metadata.height * scale)
const newWidth = Math.round(metadata.width * scale);
const newHeight = Math.round(metadata.height * scale);
return await sharp(filePath)
.resize(newWidth, newHeight)
.toFormat(convertTo)
.toFile(targetPath);
.resize(newWidth, newHeight)
.toFormat(convertTo)
.toFile(targetPath);
}
return await sharp(filePath).toFormat(convertTo).toFile(targetPath);
}
}