-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: Replace lilliput with govips #312
Conversation
Codecov Report
@@ Coverage Diff @@
## master #312 +/- ##
==========================================
+ Coverage 45.35% 45.76% +0.40%
==========================================
Files 101 100 -1
Lines 3684 3651 -33
==========================================
Hits 1671 1671
+ Misses 1965 1932 -33
Partials 48 48
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
A lot of duplicate code between the functions, needs a refactor.
AVIF is quirky.
Should these configs entries really be called like this?
I've been unable to get animated avif to work, on Windows by using the suffix -all binary distribution or on WSL/Ubuntu by rebuilding libvips with libheif-dev. Static avif files like this fox works: So does static 7TV emotes: But not animated 7TV emotes. The error I get on Windows for animated .avif is Now, 7TV does have .webp endpoints too: Their non-suffixed/non-file-format-ending version uses animated WebP which works with out of the box libvips on Ubuntu & Windows -static/-all distributions. And that preview is solved by this PR. If anyone could test, or have resources on how to figure out a solution to support animated avif, it would be very helpful. Maybe in a separate PR. Required changes for testingdiff --git a/pkg/thumbnail/thumbnail.go b/pkg/thumbnail/thumbnail.go
index d92504a..3126425 100644
--- a/pkg/thumbnail/thumbnail.go
+++ b/pkg/thumbnail/thumbnail.go
@@ -15,6 +15,7 @@ var (
"image/png",
"image/gif",
"image/webp",
+ "image/avif",
"application/pdf",
}
@@ -22,6 +23,7 @@ var (
animatedThumbnails = []string{
"image/gif",
"image/webp",
+ "image/avif",
}
cfg config.APIConfig
@@ -95,14 +97,14 @@ func BuildAnimatedThumbnail(inputBuf []byte, resp *http.Response) ([]byte, error
maxThumbnailSize := int(cfg.MaxThumbnailSize)
format := image.Format()
- if image.Width() <= maxThumbnailSize && image.Height() <= maxThumbnailSize {
+ if image.Width() <= maxThumbnailSize && image.Height() <= maxThumbnailSize && format != vips.ImageTypeAVIF {
return inputBuf, nil
}
importParams := vips.NewImportParams()
// n=-1 is used for animated images to make sure to get all frames and not just the first one.
- if format == vips.ImageTypeGIF || format == vips.ImageTypeWEBP {
+ if format == vips.ImageTypeGIF || format == vips.ImageTypeWEBP || format == vips.ImageTypeAVIF {
importParams.NumPages.Set(-1)
}
Edit: libvips/libvips#3048 (reply in thread) May be related? I'm unsure how to verify this limitation. |
Should we maybe continue supporting the |
Good point. I agree now that the
I would even argue that we should error out if the
By erroring out with a descriptive message when the old parameter is detected, we can make sure users are not running into unexpected behavior when upgrading. |
Now same location as BuildStaticThumbnail's.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than changing the logging method to what's used elsewhere, I think this looks good 👍
Wouldn't this be a change for BuildStaticThumbnail() too? If so, maybe best if done in separate PR? Also in a few more places https://github.com/Chatterino/api/search?q=fmt.Errorf & https://github.com/Chatterino/api/search?q=fmt.Println |
Yes, I should have done that in |
Pull request checklist:
CHANGELOG.md
was updated, if applicableDescription
Old text
Preview: https://streamable.com/0lu2pe
There's a few pain-points with govips (If your distro has libvips below version 8.12 you will have to build from source) but it solves several issues that lilliput has:
We can do custom outputs based on the input, which also means custom quality etc. (In video everything is exported as WebP with quality at 10%)
But, I'm just danking around. Consider this PR a proof-of-concept, maybe someone more can look into govips / vips and see how we could implement this.
For building libvips, I used the following: https://github.com/libvips/libvips/wiki/Build-for-Ubuntu
This PR brings support for animated image previews without lilliput by replacing it with a library (govips) that interfaces with libvips.
Why is this PR replacing lilliput? lilliput has several issues related to memory usage, which libvips resolves as well as issues with animated WebP that are yet to be supported even on lilliput's main contributor and user: Discord. libvips resolves both issues: See contents of "Old text" for more context.
Supported animated file formats with this PR:
Not (yet) supported animated file formats:
All inputs are currently turned into WebP to potentially save on bandwidth. One can save more bandwidth by setting a quality limit on the WebP output, but for this PR I decided to leave this out: It can be its own PR with a new config entry.
Additionally, this PR introduces another breaking change by renaming
enable-lilliput
config entry toenable-animated-thumbnails
.Test links
Animated WebP https://7tv.app/emotes/604281c81ae70f000d47ffd9
Animated WebP https://mathiasbynens.be/demo/animated-webp-supported.webp
Static WebP https://7tv.app/emotes/617142c4ffc7244d797caa57
Static WebP https://www.gstatic.com/webp/gallery/5.webp
Animated GIF https://codelabs.developers.google.com/static/codelabs/avif/images/ice_qcif_15fps.gif
Animated GIF https://media.tenor.com/2hJTw8DEzqEAAAAM/forsen-forsen-e.gif