Merge pull request #278 from atfox98/main

This commit is contained in:
Emrik Östling
2025-05-07 10:11:44 +02:00
committed by GitHub
4 changed files with 54 additions and 1 deletions

View File

@@ -53,7 +53,8 @@ RUN apk --no-cache add \
poppler-utils \
gcompat \
libva-utils \
py3-numpy
py3-numpy \
potrace
# RUN apk --no-cache add calibre@testing --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main/

View File

@@ -10,6 +10,7 @@ import { convert as convertImage, properties as propertiesImage } from "./vips";
import { convert as convertxelatex, properties as propertiesxelatex } from "./xelatex";
// import { convert as convertCalibre, properties as propertiesCalibre } from "./calibre";
import { convert as convertLibheif, properties as propertiesLibheif } from "./libheif";
import { convert as convertpotrace, properties as propertiespotrace } from "./potrace";
// This should probably be reconstructed so that the functions are not imported instead the functions hook into this to make the converters more modular
@@ -86,6 +87,10 @@ const properties: Record<
properties: propertiesFFmpeg,
converter: convertFFmpeg,
},
potrace: {
properties: propertiespotrace,
converter: convertpotrace,
},
};
export async function mainConverter(

37
src/converters/potrace.ts Normal file
View File

@@ -0,0 +1,37 @@
import { execFile } from "node:child_process";
export const properties = {
from: {
images: ["pnm", "pbm", "pgm", "bmp"],
},
to: {
images: ["svg", "pdf", "pdfpage", "eps", "postscript", "ps", "dxf", "geojson", "pgm", "gimppath", "xfig"],
},
};
export function convert(
filePath: string,
fileType: string,
convertTo: string,
targetPath: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
options?: unknown,
): Promise<string> {
return new Promise((resolve, reject) => {
execFile("potrace", [filePath, "-o", targetPath, "-b", convertTo], (error, stdout, stderr) => {
if (error) {
reject(`error: ${error}`);
}
if (stdout) {
console.log(`stdout: ${stdout}`);
}
if (stderr) {
console.error(`stderr: ${stderr}`);
}
resolve("Done");
});
});
}

View File

@@ -124,6 +124,16 @@ if (process.env.NODE_ENV === "production") {
}
});
exec("potrace -v", (error, stdout) => {
if (error) {
console.error("potrace is not installed");
}
if (stdout) {
console.log(stdout.split("\n")[0]);
}
});
exec("bun -v", (error, stdout) => {
if (error) {
console.error("Bun is not installed. wait what");