Skip to content

Encode and Decode using the libwebp library via WASM with animation support#14234

Merged
bep merged 1 commit into
gohugoio:masterfrom
bep:feat/webpwasm
Dec 16, 2025
Merged

Encode and Decode using the libwebp library via WASM with animation support#14234
bep merged 1 commit into
gohugoio:masterfrom
bep:feat/webpwasm

Conversation

@bep
Copy link
Copy Markdown
Member

@bep bep commented Dec 2, 2025

Fixes #10030
Fixes #8500
Fixes #12843
Fixes #8879
Fixes #12842

Some issues left TODO:

  • Issue with animated GIFs that I seem to have somehow broken.

@gemini-code-assist
Copy link
Copy Markdown

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

@github-actions

This comment was marked as outdated.

@bep
Copy link
Copy Markdown
Member Author

bep commented Dec 3, 2025

As to performance:

  • I have pushed an update that uses Wazero's latest con current compiler, which gets the "init WASM" step down from 130ms to 70ms on my MacBook. This is more or less the diff I see when building your test site with this branch and the master branch.
  • In the final setup we will also cache the comiled WASM files to disk (like we do for Katex) and, also, if you have the images cached to disk, it will be as fast as before.

@jmooring
Copy link
Copy Markdown
Member

jmooring commented Dec 3, 2025

Other than a stray debug statement, this looks good to me.

image

@bep bep force-pushed the feat/webpwasm branch 7 times, most recently from 5ea980b to 1533025 Compare December 15, 2025 16:00
@bep bep changed the title proof of concept: Encode and Decode using the libwebp library via WASM Encode and Decode using the libwebp library via WASM with animation support Dec 15, 2025
@bep bep force-pushed the feat/webpwasm branch 12 times, most recently from f624c3b to aa1fc0a Compare December 15, 2025 21:31
@bep bep requested a review from Copilot December 15, 2025 22:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates WebP image encoding and decoding from native Go libraries to a WASM-based implementation using libwebp, adding support for animated WebP images. The change removes the dependency on the "extended" build for WebP support, making it available in all builds.

Key changes:

  • Replaces native WebP codec with WASM-based libwebp implementation
  • Adds animation support for WebP images
  • Removes extended build requirement for WebP functionality

Reviewed changes

Copilot reviewed 36 out of 57 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tpl/images/images.go Updates image config decoding to use new codec interface
resources/resource_spec.go Integrates WASM dispatchers and exposes Imaging field
resources/images/webp/webp.go Removes old extended build WebP encoder
resources/images/webp/webp_notavailable.go Removes old non-extended build WebP stub
resources/images/config.go Updates WebP version and documentation
resources/images/imagetesting/testing.go Refactors to use new codec with animation support
resources/images/images_golden_integration_test.go Adds comprehensive WebP processing tests
resources/image_extended_test.go Removes obsolete extended-only WebP test
resources/testdata/webp/* Adds WebP test fixtures (binary files)
resources/images/testdata/images_golden/process/webp/* Adds golden image test files (binary files)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bep
Copy link
Copy Markdown
Member Author

bep commented Dec 15, 2025

@gemini-code-assist review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces WebP image processing using a WebAssembly (WASM) module, replacing the previous cgo-based implementation. This change adds support for animated WebP images. The implementation involves a new RPC-like protocol over stdin/stdout to communicate between Go and the C code in the WASM module, handling both JSON metadata and binary image data.

The overall implementation is well-structured and impressive. I've found a couple of related issues regarding the conversion between animated image formats, which I've detailed in my comments. Specifically, the conversion from animated WebP to animated GIF is not correctly implemented, and the himage.ImageFrames interface needs to be improved to support this correctly.

Comment thread common/himage/image.go
Comment thread resources/images/codec.go Outdated
@bep bep force-pushed the feat/webpwasm branch 4 times, most recently from 17e54eb to 44693e2 Compare December 16, 2025 15:48
@bep
Copy link
Copy Markdown
Member Author

bep commented Dec 16, 2025

@gemini-code-assist review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces WebP image processing support using a WebAssembly (WASM) module, replacing the previous CGo-based implementation. This is a significant improvement for portability. The changes include a new communication protocol between Go and the WASM module to handle binary data streams, new interfaces for animated images, and a centralization of image codec logic. The implementation is extensive and well-structured. I've found one critical issue in the C code of the WASM module that could lead to a crash. Other than that, the changes look solid.

Comment thread internal/warpc/genwebp/webp.c Outdated
@bep
Copy link
Copy Markdown
Member Author

bep commented Dec 16, 2025

@gemini-code-assist review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant and well-executed refactoring to handle WebP image processing using WebAssembly (WASM) instead of CGo. This change enables WebP support, including animations, across all Hugo versions, not just the extended one. The implementation includes a new WASM RPC communication layer that supports binary data streams, a generic image codec abstraction, and new interfaces for animated images. The changes are extensive and touch many parts of the codebase related to image processing and resource handling. I've found one critical issue related to goroutine variable capturing that needs to be addressed. Otherwise, the changes look solid and the addition of tests is commendable.

Comment thread internal/warpc/warpc.go
@bep bep merged commit 1b4514e into gohugoio:master Dec 16, 2025
6 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants