diff --git a/Dockerfile b/Dockerfile index ef26bb6..cb3b84f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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/ diff --git a/src/converters/main.ts b/src/converters/main.ts index d73593b..3c745f6 100644 --- a/src/converters/main.ts +++ b/src/converters/main.ts @@ -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( diff --git a/src/converters/potrace.ts b/src/converters/potrace.ts new file mode 100644 index 0000000..0c145a7 --- /dev/null +++ b/src/converters/potrace.ts @@ -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 { + 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"); + }); + }); + } \ No newline at end of file diff --git a/src/helpers/printVersions.ts b/src/helpers/printVersions.ts index acf3907..312b56b 100644 --- a/src/helpers/printVersions.ts +++ b/src/helpers/printVersions.ts @@ -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");