Merge pull request #31 from C4illin/feature-libjxl

This commit is contained in:
Emrik Östling 2024-06-11 19:36:52 +02:00 committed by GitHub
commit 15d4233a82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 140 additions and 8 deletions

51
Debian.Dockerfile Normal file
View file

@ -0,0 +1,51 @@
FROM oven/bun:1-debian as base
WORKDIR /app
# install dependencies into temp directory
# this will cache them and speed up future builds
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile
# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production
# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
# FROM base AS prerelease
# COPY --from=install /temp/dev/node_modules node_modules
# COPY . .
# # [optional] tests & build
# ENV NODE_ENV=production
# RUN bun test
# RUN bun run build
# copy production dependencies and source code into final image
FROM base AS release
LABEL maintainer="Emrik Östling (C4illin)"
LABEL description="ConvertX: self-hosted online file converter supporting 700+ file formats."
LABEL repo="https://github.com/C4illin/ConvertX"
# install additional dependencies
RUN rm -rf /var/lib/apt/lists/partial && apt-get update -o Acquire::CompressionTypes::Order::=gz \
&& apt-get install -y \
pandoc \
texlive-latex-recommended \
texlive-fonts-recommended \
texlive-latex-extra \
ffmpeg \
graphicsmagick \
ghostscript \
libvips-tools
COPY --from=install /temp/prod/node_modules node_modules
# COPY --from=prerelease /app/src/index.tsx /app/src/
# COPY --from=prerelease /app/package.json .
COPY . .
EXPOSE 3000/tcp
ENTRYPOINT [ "bun", "run", "./src/index.tsx" ]

View file

@ -1,4 +1,4 @@
FROM oven/bun:1-debian as base FROM oven/bun:1-alpine as base
WORKDIR /app WORKDIR /app
# install dependencies into temp directory # install dependencies into temp directory
@ -31,16 +31,16 @@ LABEL description="ConvertX: self-hosted online file converter supporting 700+ f
LABEL repo="https://github.com/C4illin/ConvertX" LABEL repo="https://github.com/C4illin/ConvertX"
# install additional dependencies # install additional dependencies
RUN rm -rf /var/lib/apt/lists/partial && apt-get update -o Acquire::CompressionTypes::Order::=gz \ RUN apk update && apk add --no-cache \
&& apt-get install -y \
pandoc \ pandoc \
texlive-latex-recommended \ texlive \
texlive-fonts-recommended \ texmf-dist-fontsextra \
texlive-latex-extra \ texmf-dist-latexextra \
ffmpeg \ ffmpeg \
graphicsmagick \ graphicsmagick \
ghostscript \ ghostscript \
libvips-tools vips-tools \
libjxl-tools
COPY --from=install /temp/prod/node_modules node_modules COPY --from=install /temp/prod/node_modules node_modules
# COPY --from=prerelease /app/src/index.tsx /app/src/ # COPY --from=prerelease /app/src/index.tsx /app/src/

View file

@ -19,7 +19,8 @@ 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 |
|------------------------------------------------------------------------------|---------------|---------------|-------------| |------------------------------------------------------------------------------|---------------|---------------|-------------|
| [Vips](https://github.com/libvips/libvips) | Images (fast) | 45 | 23 | | [libjxl](https://github.com/libjxl/libjxl) | Images | 11 | 11 |
| [Vips](https://github.com/libvips/libvips) | Images | 45 | 23 |
| [PDFLaTeX](https://www.math.rug.nl/~trentelman/jacob/pdflatex/pdflatex.html) | Documents | 1 | 1 | | [PDFLaTeX](https://www.math.rug.nl/~trentelman/jacob/pdflatex/pdflatex.html) | Documents | 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 |

71
src/converters/libjxl.ts Normal file
View file

@ -0,0 +1,71 @@
import { exec } from "node:child_process";
// declare possible conversions
export const properties = {
from: {
jxl: ["jxl"],
images: [
"apng",
"exr",
"gif",
"jpeg",
"pam",
"pfm",
"pgm",
"pgx",
"png",
"ppm",
],
},
to: {
jxl: [
"apng",
"exr",
"gif",
"jpeg",
"pam",
"pfm",
"pgm",
"pgx",
"png",
"ppm",
],
images: ["jxl"],
},
};
export function convert(
filePath: string,
fileType: string,
convertTo: string,
targetPath: string,
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
options?: any,
): Promise<string> {
let tool = "";
if (fileType === "jxl") {
tool = "djxl";
}
if (convertTo === "jxl") {
tool = "cjxl";
}
return new Promise((resolve, reject) => {
exec(`${tool} "${filePath}" "${targetPath}"`, (error, stdout, stderr) => {
if (error) {
reject(`error: ${error}`);
}
if (stdout) {
console.log(`stdout: ${stdout}`);
}
if (stderr) {
console.error(`stderr: ${stderr}`);
}
resolve("success");
});
});
}

View file

@ -20,6 +20,11 @@ import {
properties as propertiesPdflatex, properties as propertiesPdflatex,
} from "./pdflatex"; } from "./pdflatex";
import {
convert as convertLibjxl,
properties as propertiesLibjxl,
} from "./libjxl";
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
@ -50,6 +55,10 @@ const properties: {
) => any; ) => any;
}; };
} = { } = {
libjxl: {
properties: propertiesLibjxl,
converter: convertLibjxl,
},
vips: { vips: {
properties: propertiesImage, properties: propertiesImage,
converter: convertImage, converter: convertImage,