Skip to content

Commit f738a82

Browse files
committed
proof of concept: Encode and Decode using the libwebp library via WASM
Note that this works, but the building blocks are quickly thrown together just to get a sense if this makes sense to go forward with. See #12843
1 parent bf42138 commit f738a82

File tree

7 files changed

+14
-43
lines changed

7 files changed

+14
-43
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ require (
2222
github.com/bep/overlayfs v0.10.0
2323
github.com/bep/simplecobra v0.6.1
2424
github.com/bep/tmc v0.5.1
25+
github.com/bep/webptemp v0.0.0-20251202110834-92f833957f2b
2526
github.com/bits-and-blooms/bitset v1.24.4
2627
github.com/cespare/xxhash/v2 v2.3.0
2728
github.com/clbanning/mxj/v2 v2.7.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ github.com/bep/simplecobra v0.6.1 h1:ORBAC5CSar99/NPZ5fCthCx/uvlm7ry58wwDsZ23a20
178178
github.com/bep/simplecobra v0.6.1/go.mod h1:hmtjyHv6xwD637ScIRP++0NKkR5szrHuMw5BxMUH66s=
179179
github.com/bep/tmc v0.5.1 h1:CsQnSC6MsomH64gw0cT5f+EwQDcvZz4AazKunFwTpuI=
180180
github.com/bep/tmc v0.5.1/go.mod h1:tGYHN8fS85aJPhDLgXETVKp+PR382OvFi2+q2GkGsq0=
181+
github.com/bep/webptemp v0.0.0-20251202110834-92f833957f2b h1:yy1aEC9FSn35GsninCuHIEiXXh2dbwc579NVgXVLUkA=
182+
github.com/bep/webptemp v0.0.0-20251202110834-92f833957f2b/go.mod h1:v75l/Bf01VyaXGbNjpxF96GD/pgdp6v9fkRCfdMtQrQ=
181183
github.com/bep/workers v1.0.0 h1:U+H8YmEaBCEaFZBst7GcRVEoqeRC9dzH2dWOwGmOchg=
182184
github.com/bep/workers v1.0.0/go.mod h1:7kIESOB86HfR2379pwoMWNy8B50D7r99fRLUyPSNyCs=
183185
github.com/bits-and-blooms/bitset v1.24.4 h1:95H15Og1clikBrKr/DuzMXkQzECs1M6hhoGXLwLQOZE=

resources/image.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242
"github.com/gohugoio/hugo/resources/images"
4343

4444
// Blind import for image.Decode
45-
_ "golang.org/x/image/webp"
45+
_ "github.com/bep/webptemp"
4646
)
4747

4848
var (

resources/image_extended_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14-
//go:build extended
15-
1614
package resources_test
1715

1816
import (

resources/images/webp/webp.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,27 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14-
//go:build extended
15-
1614
package webp
1715

1816
import (
1917
"image"
2018
"io"
2119

22-
"github.com/bep/gowebp/libwebp"
20+
webp "github.com/bep/webptemp"
21+
2322
"github.com/bep/gowebp/libwebp/webpoptions"
2423
)
2524

2625
// Encode writes the Image m to w in Webp format with the given
2726
// options.
2827
func Encode(w io.Writer, m image.Image, o webpoptions.EncodingOptions) error {
29-
return libwebp.Encode(w, m, o)
28+
oo := webp.Options{
29+
Lossless: false,
30+
Quality: o.Quality,
31+
Method: 4,
32+
Exact: false,
33+
}
34+
return webp.Encode(w, m, oo)
3035
}
3136

3237
// Supports returns whether webp encoding is supported in this build.

resources/images/webp/webp_notavailable.go

Lines changed: 0 additions & 35 deletions
This file was deleted.

tpl/images/images.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
_ "image/png"
3636

3737
// Import webp codec
38-
_ "golang.org/x/image/webp"
38+
_ "github.com/bep/webptemp"
3939

4040
"github.com/gohugoio/hugo/deps"
4141
"github.com/spf13/afero"

0 commit comments

Comments
 (0)