Skip to content
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

Support AVIF format encoding #70

Merged
merged 9 commits into from
Feb 5, 2025
Merged

Support AVIF format encoding #70

merged 9 commits into from
Feb 5, 2025

Conversation

supercaracal
Copy link
Contributor

@supercaracal supercaracal commented Jan 31, 2025

URL Size Time
http://localhost:3000/Lenna.jpg?w=1618&h=1000 116KB 123ms
http://localhost:3000/Lenna.jpg?w=1618&h=1000&avif=true&quality=100 606KB 660ms
http://localhost:3000/Lenna.jpg?w=1618&h=1000&avif=true&quality=50 85.4KB 551ms
http://localhost:3000/Lenna.jpg?w=1618&h=1000&avif=true&quality=20 11.8KB 421ms

Although my monitor is cheap, it looks to me the image quality might be fine even if the quality is 20. The compression ratio is awesome but the encoding speed is slower. The lossless is useless for us. Since WebP is well-balanced, I think we should prior WebP than AVIF when both are specified in a query string. I implemented only an encoding feature for AVIF bacause I think it is a rare case that the format is being a source image.

@supercaracal supercaracal marked this pull request as ready for review January 31, 2025 07:42
@supercaracal supercaracal requested a review from etsxxx January 31, 2025 07:42
@@ -133,29 +133,44 @@ func MainHandler(w http.ResponseWriter, r *http.Request, conf *configure.Conf, l
case "jpeg":
if q.UseWebP() {
err = imageprocessor.EncodeWebP(w, img.GetImg(), q.Quality(), false)
} else if q.UseAVIF() {
w.Header().Set("Content-Type", "image/avif")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Browser downloads the response body as a file if the explicit header specification is none.

Copy link
Member

@etsxxx etsxxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!


opts := avif.Options{
Threads: 0, // all available cores
Speed: avif.MaxSpeed, // bigger is faster, but lower compress ratio
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: ‏Considering the compression speed of AVIF, I agree with you that the default is speed first.

@supercaracal supercaracal merged commit 2f083e7 into master Feb 5, 2025
2 checks passed
@supercaracal supercaracal deleted the support-avif branch February 5, 2025 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants