mirror of
https://github.com/C4illin/ConvertX.git
synced 2025-11-04 14:03:32 +00:00
feat: add resvg converter
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
FROM oven/bun:1.1.25-alpine AS base
|
FROM oven/bun:1.1.25-alpine AS base
|
||||||
|
LABEL org.opencontainers.image.source="https://github.com/C4illin/ConvertX"
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# install dependencies into temp directory
|
# install dependencies into temp directory
|
||||||
@@ -13,6 +14,12 @@ RUN mkdir -p /temp/prod
|
|||||||
COPY package.json bun.lockb /temp/prod/
|
COPY package.json bun.lockb /temp/prod/
|
||||||
RUN cd /temp/prod && bun install --frozen-lockfile --production
|
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
|
# copy node_modules from temp directory
|
||||||
# then copy all (non-ignored) project files into the image
|
# then copy all (non-ignored) project files into the image
|
||||||
# FROM base AS prerelease
|
# FROM base AS prerelease
|
||||||
@@ -48,6 +55,7 @@ RUN apk --no-cache add \
|
|||||||
# texmf-dist-fontsextra \
|
# texmf-dist-fontsextra \
|
||||||
|
|
||||||
COPY --from=install /temp/prod/node_modules node_modules
|
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/src/index.tsx /app/src/
|
||||||
# COPY --from=prerelease /app/package.json .
|
# COPY --from=prerelease /app/package.json .
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|||||||
@@ -20,8 +20,9 @@ A self-hosted online file converter. Supports 831 different formats. Written wit
|
|||||||
| Converter | Use case | Converts from | Converts to |
|
| Converter | Use case | Converts from | Converts to |
|
||||||
|------------------------------------------------------------------------------|---------------|---------------|-------------|
|
|------------------------------------------------------------------------------|---------------|---------------|-------------|
|
||||||
| [libjxl](https://github.com/libjxl/libjxl) | JPEG XL | 11 | 11 |
|
| [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 |
|
| [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 |
|
| [Pandoc](https://pandoc.org/) | Documents | 43 | 65 |
|
||||||
| [GraphicsMagick](http://www.graphicsmagick.org/) | Images | 166 | 133 |
|
| [GraphicsMagick](http://www.graphicsmagick.org/) | Images | 166 | 133 |
|
||||||
| [FFmpeg](https://ffmpeg.org/) | Video | ~473 | ~280 |
|
| [FFmpeg](https://ffmpeg.org/) | Video | ~473 | ~280 |
|
||||||
|
|||||||
@@ -25,6 +25,11 @@ import {
|
|||||||
properties as propertiesLibjxl,
|
properties as propertiesLibjxl,
|
||||||
} from "./libjxl";
|
} from "./libjxl";
|
||||||
|
|
||||||
|
import {
|
||||||
|
convert as convertresvg,
|
||||||
|
properties as propertiesresvg,
|
||||||
|
} from "./resvg";
|
||||||
|
|
||||||
import { normalizeFiletype } from "../helpers/normalizeFiletype";
|
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
|
// This should probably be reconstructed so that the functions are not imported instead the functions hook into this to make the converters more modular
|
||||||
@@ -59,6 +64,10 @@ const properties: {
|
|||||||
properties: propertiesLibjxl,
|
properties: propertiesLibjxl,
|
||||||
converter: convertLibjxl,
|
converter: convertLibjxl,
|
||||||
},
|
},
|
||||||
|
resvg: {
|
||||||
|
properties: propertiesresvg,
|
||||||
|
converter: convertresvg,
|
||||||
|
},
|
||||||
vips: {
|
vips: {
|
||||||
properties: propertiesImage,
|
properties: propertiesImage,
|
||||||
converter: convertImage,
|
converter: convertImage,
|
||||||
|
|||||||
41
src/converters/resvg.ts
Normal file
41
src/converters/resvg.ts
Normal file
@@ -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");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -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) => {
|
exec("bun -v", (error, stdout) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error("Bun is not installed. wait what");
|
console.error("Bun is not installed. wait what");
|
||||||
|
|||||||
Reference in New Issue
Block a user