Переглянути джерело

Merge pull request #186 from C10udburst/main

feat: add inkscape for vector images
Emrik Östling 8 місяців тому
батько
коміт
d0ce307f94
5 змінених файлів з 82 додано та 1 видалено
  1. 2 1
      Dockerfile
  2. 1 0
      README.md
  3. 64 0
      src/converters/inkscape.ts
  4. 5 0
      src/converters/main.ts
  5. 10 0
      src/helpers/printVersions.ts

+ 2 - 1
Dockerfile

@@ -50,7 +50,8 @@ RUN apk --no-cache add  \
   vips-poppler \
   vips-jxl \
   libjxl-tools \
-  assimp
+  assimp \
+  inkscape
 
 # this might be needed for some latex use cases, will add it if needed.
 #   texmf-dist-fontsextra \

+ 1 - 0
README.md

@@ -30,6 +30,7 @@ A self-hosted online file converter. Supports over a thousand different formats.
 | [XeLaTeX](https://tug.org/xetex/)                                            | LaTeX         | 1             | 1           |
 | [Pandoc](https://pandoc.org/)                                                | Documents     | 43            | 65          |
 | [GraphicsMagick](http://www.graphicsmagick.org/)                             | Images        | 166           | 133         |
+| [Inkscape](https://inkscape.org/)                                            | Vector images | 7             | 17          |
 | [FFmpeg](https://ffmpeg.org/)                                                | Video         | ~473          | ~280        |
 
 <!-- many ffmpeg fileformats are duplicates -->

+ 64 - 0
src/converters/inkscape.ts

@@ -0,0 +1,64 @@
+import { exec } from "node:child_process";
+
+export const properties = {
+    from: {
+      images: [
+        "svg",
+        "pdf",
+        "eps",
+        "ps",
+        "wmf",
+        "emf",
+        "png"
+      ]
+    },
+    to: {
+      images: [
+        "dxf",
+        "emf",
+        "eps",
+        "fxg",
+        "gpl",
+        "hpgl",
+        "html",
+        "odg",
+        "pdf",
+        "png",
+        "pov",
+        "ps",
+        "sif",
+        "svg",
+        "svgz",
+        "tex",
+        "wmf",
+      ]
+    },
+  };
+
+  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) => {
+      exec(`inkscape "${filePath}" -o "${targetPath}"`, (error, stdout, stderr) => {
+        if (error) {
+          reject(`error: ${error}`);
+        }
+  
+        if (stdout) {
+          console.log(`stdout: ${stdout}`);
+        }
+  
+        if (stderr) {
+          console.error(`stderr: ${stderr}`);
+        }
+  
+        resolve("Done");
+      });
+    });
+  }
+  

+ 5 - 0
src/converters/main.ts

@@ -2,6 +2,7 @@ import { normalizeFiletype } from "../helpers/normalizeFiletype";
 import { convert as convertassimp, properties as propertiesassimp } from "./assimp";
 import { convert as convertFFmpeg, properties as propertiesFFmpeg } from "./ffmpeg";
 import { convert as convertGraphicsmagick, properties as propertiesGraphicsmagick } from "./graphicsmagick";
+import { convert as convertInkscape, properties as propertiesInkscape } from "./inkscape";
 import { convert as convertLibjxl, properties as propertiesLibjxl } from "./libjxl";
 import { convert as convertPandoc, properties as propertiesPandoc } from "./pandoc";
 import { convert as convertresvg, properties as propertiesresvg } from "./resvg";
@@ -63,6 +64,10 @@ const properties: Record<
     properties: propertiesGraphicsmagick,
     converter: convertGraphicsmagick,
   },
+  inkscape: {
+    properties: propertiesInkscape,
+    converter: convertInkscape,
+  },
   assimp: {
     properties: propertiesassimp,
     converter: convertassimp,

+ 10 - 0
src/helpers/printVersions.ts

@@ -53,6 +53,16 @@ if (process.env.NODE_ENV === "production") {
     }
   });
 
+  exec("inkscape --version", (error, stdout) => {
+    if (error) {
+      console.error("Inkscape is not installed.");
+    }
+
+    if (stdout) {
+      console.log(stdout.split("\n")[0]);
+    }
+  });
+
   exec("djxl --version", (error, stdout) => {
     if (error) {
       console.error("libjxl-tools is not installed.");