Skip to content

Commit

Permalink
feat: add inkscape for vector images
Browse files Browse the repository at this point in the history
  • Loading branch information
C10udburst committed Nov 16, 2024
1 parent b485bc9 commit f3740e9
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand Down
64 changes: 64 additions & 0 deletions src/converters/inkscape.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions src/converters/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -63,6 +64,10 @@ const properties: Record<
properties: propertiesGraphicsmagick,
converter: convertGraphicsmagick,
},
inkscape: {
properties: propertiesInkscape,
converter: convertInkscape,
},
assimp: {
properties: propertiesassimp,
converter: convertassimp,
Expand Down
10 changes: 10 additions & 0 deletions src/helpers/printVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down

0 comments on commit f3740e9

Please sign in to comment.