Skip to content

Commit

Permalink
feat: add resvg converter
Browse files Browse the repository at this point in the history
  • Loading branch information
C4illin committed Aug 23, 2024
1 parent 7456174 commit d5eeef9
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM oven/bun:1.1.25-alpine AS base
LABEL org.opencontainers.image.source="https://github.com/C4illin/ConvertX"
WORKDIR /app

# install dependencies into temp directory
Expand All @@ -13,6 +14,12 @@ RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production

FROM base AS builder
RUN apk --no-cache add curl gcc
ENV PATH=/root/.cargo/bin:$PATH
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
RUN cargo install resvg

# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
# FROM base AS prerelease
Expand Down Expand Up @@ -48,6 +55,7 @@ RUN apk --no-cache add \
# texmf-dist-fontsextra \

COPY --from=install /temp/prod/node_modules node_modules
COPY --from=builder /root/.cargo/bin/resvg /usr/local/bin/resvg
# COPY --from=prerelease /app/src/index.tsx /app/src/
# COPY --from=prerelease /app/package.json .
COPY . .
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ A self-hosted online file converter. Supports 831 different formats. Written wit
| Converter | Use case | Converts from | Converts to |
|------------------------------------------------------------------------------|---------------|---------------|-------------|
| [libjxl](https://github.com/libjxl/libjxl) | JPEG XL | 11 | 11 |
| [resvg](https://github.com/RazrFalcon/resvg) | SVG | 1 | 1 |
| [Vips](https://github.com/libvips/libvips) | Images | 45 | 23 |
| [XeLaTeX](https://tug.org/xetex/) | Documents | 1 | 1 |
| [XeLaTeX](https://tug.org/xetex/) | LaTeX | 1 | 1 |
| [Pandoc](https://pandoc.org/) | Documents | 43 | 65 |
| [GraphicsMagick](http://www.graphicsmagick.org/) | Images | 166 | 133 |
| [FFmpeg](https://ffmpeg.org/) | Video | ~473 | ~280 |
Expand Down
9 changes: 9 additions & 0 deletions src/converters/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ import {
properties as propertiesLibjxl,
} from "./libjxl";

import {
convert as convertresvg,
properties as propertiesresvg,
} from "./resvg";

import { normalizeFiletype } from "../helpers/normalizeFiletype";

// This should probably be reconstructed so that the functions are not imported instead the functions hook into this to make the converters more modular
Expand Down Expand Up @@ -59,6 +64,10 @@ const properties: {
properties: propertiesLibjxl,
converter: convertLibjxl,
},
resvg: {
properties: propertiesresvg,
converter: convertresvg,
},
vips: {
properties: propertiesImage,
converter: convertImage,
Expand Down
41 changes: 41 additions & 0 deletions src/converters/resvg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { exec } from "node:child_process";

export const properties = {
from: {
images: ["svg"],
},
to: {
images: ["png"],
},
};


export function convert(
filePath: string,
fileType: string,
convertTo: string,
targetPath: string,
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
options?: any,
): Promise<string> {
return new Promise((resolve, reject) => {
exec(
`resvg "${filePath}" "${targetPath}"`,
(error, stdout, stderr) => {
if (error) {
reject(`error: ${error}`);
}

if (stdout) {
console.log(`stdout: ${stdout}`);
}

if (stderr) {
console.error(`stderr: ${stderr}`);
}

resolve("success");
},
);
});
}
10 changes: 10 additions & 0 deletions src/helpers/printVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ if (process.env.NODE_ENV === "production") {
}
});

exec("resvg -V", (error, stdout) => {
if (error) {
console.error("resvg is not installed");
}

if (stdout) {
console.log(`resvg v${stdout.split("\n")[0]}`);
}
});

exec("bun -v", (error, stdout) => {
if (error) {
console.error("Bun is not installed. wait what");
Expand Down

0 comments on commit d5eeef9

Please sign in to comment.