jsx working

This commit is contained in:
C4illin 2024-05-19 00:07:56 +02:00
parent 0f0bc6c4e5
commit a68046ecd6
19 changed files with 814 additions and 458 deletions

37
src/converters/sharp.ts Normal file
View file

@ -0,0 +1,37 @@
import sharp from "sharp";
// declare possible conversions
export const properties = {
from: ["jpeg", "png", "webp", "gif", "avif", "tiff", "svg"],
to: ["jpeg", "png", "webp", "gif", "avif", "tiff"],
options: {
svg: {
scale: {
description: "Scale the image up or down",
type: "number",
default: 1,
},
}
}
}
export async function convert(filePath: string, fileType: string, convertTo: string, targetPath: string, options?: any) {
if (fileType === "svg") {
const scale = options.scale || 1;
const metadata = await sharp(filePath).metadata();
if (!metadata || !metadata.width || !metadata.height) {
throw new Error("Could not get metadata from image");
}
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);
}
return await sharp(filePath).toFormat(convertTo).toFile(targetPath);
}