Skip to content

Commit 6b92540

Browse files
authored
Merge pull request #225 from C4illin/fix/#202/add-libheif
fix: add libheif
2 parents eacded6 + decfea5 commit 6b92540

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ RUN apk --no-cache add \
4949
vips-tools \
5050
vips-poppler \
5151
vips-jxl \
52+
vips-heif \
53+
vips-magick \
5254
libjxl-tools \
5355
assimp \
5456
inkscape \
5557
poppler-utils \
5658
gcompat \
5759
libva-utils \
58-
py3-numpy
60+
py3-numpy \
61+
libheif-tools
5962

6063
RUN apk --no-cache add qt6-qtbase-private-dev --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community/
6164

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ A self-hosted online file converter. Supports over a thousand different formats.
2626
|------------------------------------------------------------------------------|---------------|---------------|-------------|
2727
| [libjxl](https://github.com/libjxl/libjxl) | JPEG XL | 11 | 11 |
2828
| [resvg](https://github.com/RazrFalcon/resvg) | SVG | 1 | 1 |
29+
| [libheif](https://github.com/strukturag/libheif) | HEIF | 7 | 6 |
2930
| [Vips](https://github.com/libvips/libvips) | Images | 45 | 23 |
3031
| [XeLaTeX](https://tug.org/xetex/) | LaTeX | 1 | 1 |
3132
| [Calibre](https://calibre-ebook.com/) | E-books | 26 | 19 |

src/converters/libheif.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { execFile } from "child_process";
2+
3+
export const properties = {
4+
from: {
5+
images: [
6+
"avci",
7+
"avcs",
8+
"avif",
9+
"h264",
10+
"heic",
11+
"heics",
12+
"heif",
13+
"heifs",
14+
"mkv",
15+
"mp4",
16+
],
17+
},
18+
to: {
19+
images: ["jpeg", "png", "y4m"],
20+
},
21+
};
22+
23+
export function convert(
24+
filePath: string,
25+
fileType: string,
26+
convertTo: string,
27+
targetPath: string,
28+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
29+
options?: unknown,
30+
): Promise<string> {
31+
return new Promise((resolve, reject) => {
32+
execFile(
33+
"heif-convert",
34+
[filePath, targetPath],
35+
(error, stdout, stderr) => {
36+
if (error) {
37+
reject(`error: ${error}`);
38+
}
39+
40+
if (stdout) {
41+
console.log(`stdout: ${stdout}`);
42+
}
43+
44+
if (stderr) {
45+
console.error(`stderr: ${stderr}`);
46+
}
47+
48+
resolve("Done");
49+
},
50+
);
51+
});
52+
}

src/converters/main.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { convert as convertresvg, properties as propertiesresvg } from "./resvg"
99
import { convert as convertImage, properties as propertiesImage } from "./vips";
1010
import { convert as convertxelatex, properties as propertiesxelatex } from "./xelatex";
1111
import { convert as convertCalibre, properties as propertiesCalibre } from "./calibre";
12+
import { convert as convertLibheif, properties as propertiesLibheif } from "./libheif";
1213

1314

1415
// This should probably be reconstructed so that the functions are not imported instead the functions hook into this to make the converters more modular
@@ -49,6 +50,10 @@ const properties: Record<
4950
properties: propertiesresvg,
5051
converter: convertresvg,
5152
},
53+
libheif: {
54+
properties: propertiesLibheif,
55+
converter: convertLibheif,
56+
},
5257
vips: {
5358
properties: propertiesImage,
5459
converter: convertImage,

0 commit comments

Comments
 (0)