Skip to content

Commit

Permalink
Add support for JPEG XL image format (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDecryptor committed May 28, 2021
1 parent 07101ac commit 57ecf2d
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core.d.ts
Expand Up @@ -140,6 +140,7 @@ declare namespace core {
| 'chm'
| '3mf'
| 'zst'
| 'jxl'
| 'vcf';

type MimeType =
Expand Down Expand Up @@ -274,6 +275,7 @@ declare namespace core {
| 'model/stl'
| 'application/vnd.ms-htmlhelp'
| 'model/3mf'
| 'image/jxl'
| 'application/zstd';

interface FileTypeResult {
Expand Down
10 changes: 10 additions & 0 deletions core.js
Expand Up @@ -1162,6 +1162,16 @@ async function _fromTokenizer(tokenizer) {
}
}

if (
check([0xFF, 0x0A]) ||
check([0x00, 0x00, 0x00, 0x0C, 0x4A, 0x58, 0x4C, 0x20, 0x0D, 0x0A, 0x87, 0x0A])
) {
return {
ext: 'jxl',
mime: 'image/jxl'
};
}

// -- Unsafe signatures --

if (
Expand Down
Binary file added fixture/fixture.jxl
Binary file not shown.
Binary file added fixture/fixture2.jxl
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -184,6 +184,7 @@
"chm",
"3mf",
"zst",
"jxl",
"vcf"
],
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions readme.md
Expand Up @@ -409,6 +409,7 @@ Returns a set of supported MIME types.
- [`stl`](https://en.wikipedia.org/wiki/STL_(file_format)) - Standard Tesselated Geometry File Format (ASCII only)
- [`chm`](https://en.wikipedia.org/wiki/Microsoft_Compiled_HTML_Help) - Microsoft Compiled HTML Help
- [`3mf`](https://en.wikipedia.org/wiki/3D_Manufacturing_Format) - 3D Manufacturing Format
- [`jxl`](https://en.wikipedia.org/wiki/JPEG_XL) - JPEG XL image format

*Pull requests are welcome for additional commonly used file types.*

Expand Down
2 changes: 2 additions & 0 deletions supported.js
Expand Up @@ -138,6 +138,7 @@ module.exports = {
'chm',
'3mf',
'zst',
'jxl',
'vcf'
],
mimeTypes: [
Expand Down Expand Up @@ -272,6 +273,7 @@ module.exports = {
'model/stl',
'application/vnd.ms-htmlhelp',
'model/3mf',
'image/jxl',
'application/zstd'
]
};
4 changes: 4 additions & 0 deletions test.js
Expand Up @@ -189,6 +189,10 @@ const names = {
'fixture-normal', // Normal AI
'fixture-without-pdf-compatibility' // AI without the PDF compatibility (cannot be opened by PDF viewers I guess)
],
jxl: [
'fixture', // Image data stored within JXL container
'fixture2' // Bare image data with no container
],
pdf: [
'fixture',
'fixture-adobe-illustrator', // PDF saved from Adobe Illustrator, using the default "[Illustrator Default]" preset
Expand Down

0 comments on commit 57ecf2d

Please sign in to comment.