Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
matrix-media-repo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
matrix-media-repo
Commits
c6f18e91
Commit
c6f18e91
authored
3 years ago
by
Travis Ralston
Browse files
Options
Downloads
Patches
Plain Diff
Support JPEG XL
Fixes
https://github.com/turt2live/matrix-media-repo/issues/355
parent
d6e4cf1c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
thumbnailing/i/jpegxl.go
+69
-0
69 additions, 0 deletions
thumbnailing/i/jpegxl.go
with
70 additions
and
0 deletions
CHANGELOG.md
+
1
−
0
View file @
c6f18e91
...
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
...
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Added
### Added
*
New config option to set user agent when requesting URL previews.
*
New config option to set user agent when requesting URL previews.
*
Added support for
`image/jxl`
thumbnailing.
### Fixed
### Fixed
...
...
This diff is collapsed.
Click to expand it.
thumbnailing/i/jpegxl.go
0 → 100644
+
69
−
0
View file @
c6f18e91
package
i
import
(
"errors"
"io/ioutil"
"os"
"os/exec"
"path"
"github.com/turt2live/matrix-media-repo/common/rcontext"
"github.com/turt2live/matrix-media-repo/thumbnailing/m"
"github.com/turt2live/matrix-media-repo/util"
"github.com/turt2live/matrix-media-repo/util/cleanup"
)
type
jpegxlGenerator
struct
{
}
func
(
d
jpegxlGenerator
)
supportedContentTypes
()
[]
string
{
return
[]
string
{
"image/jxl"
}
}
func
(
d
jpegxlGenerator
)
supportsAnimation
()
bool
{
return
false
}
func
(
d
jpegxlGenerator
)
matches
(
img
[]
byte
,
contentType
string
)
bool
{
return
contentType
==
"image/jxl"
}
func
(
d
jpegxlGenerator
)
GetOriginDimensions
(
b
[]
byte
,
contentType
string
,
ctx
rcontext
.
RequestContext
)
(
bool
,
int
,
int
,
error
)
{
return
false
,
0
,
0
,
nil
}
func
(
d
jpegxlGenerator
)
GenerateThumbnail
(
b
[]
byte
,
contentType
string
,
width
int
,
height
int
,
method
string
,
animated
bool
,
ctx
rcontext
.
RequestContext
)
(
*
m
.
Thumbnail
,
error
)
{
key
,
err
:=
util
.
GenerateRandomString
(
16
)
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"jpegxl: error generating temp key: "
+
err
.
Error
())
}
tempFile1
:=
path
.
Join
(
os
.
TempDir
(),
"media_repo."
+
key
+
".1.jpegxl"
)
tempFile2
:=
path
.
Join
(
os
.
TempDir
(),
"media_repo."
+
key
+
".2.png"
)
defer
os
.
Remove
(
tempFile1
)
defer
os
.
Remove
(
tempFile2
)
f
,
err
:=
os
.
OpenFile
(
tempFile1
,
os
.
O_RDWR
|
os
.
O_CREATE
,
0640
)
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"jpegxl: error writing temp jpegxl file: "
+
err
.
Error
())
}
_
,
_
=
f
.
Write
(
b
)
cleanup
.
DumpAndCloseStream
(
f
)
err
=
exec
.
Command
(
"convert"
,
tempFile1
,
tempFile2
)
.
Run
()
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"jpegxl: error converting jpegxl file: "
+
err
.
Error
())
}
b
,
err
=
ioutil
.
ReadFile
(
tempFile2
)
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"jpegxl: error reading temp png file: "
+
err
.
Error
())
}
return
pngGenerator
{}
.
GenerateThumbnail
(
b
,
"image/png"
,
width
,
height
,
method
,
false
,
ctx
)
}
func
init
()
{
generators
=
append
(
generators
,
jpegxlGenerator
{})
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment