fix(webp): fix installing newer version of webp

This commit is contained in:
Antoine Aflalo
2025-09-09 11:37:13 -04:00
parent 7047710fdd
commit 9a8a9693fb
2 changed files with 22 additions and 2 deletions

7
.vscode/launch.json vendored
View File

@@ -4,6 +4,13 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${file}"
},
{
"name": "Optimize Testdata",
"type": "go",

View File

@@ -1,10 +1,13 @@
package webp
import (
"github.com/belphemur/go-webpbin/v2"
"fmt"
"image"
"io"
"strings"
"sync"
"github.com/belphemur/go-webpbin/v2"
)
const libwebpVersion = "1.6.0"
@@ -15,8 +18,18 @@ func PrepareEncoder() error {
prepareMutex.Lock()
defer prepareMutex.Unlock()
container := webpbin.NewCWebP(webpbin.SetLibVersion(libwebpVersion))
return container.BinWrapper.Run()
version, err := container.Version()
if err != nil {
return err
}
if !strings.HasPrefix(version, libwebpVersion) {
return fmt.Errorf("unexpected webp version: got %s, want %s", version, libwebpVersion)
}
return nil
}
func Encode(w io.Writer, m image.Image, quality uint) error {
return webpbin.NewCWebP(webpbin.SetLibVersion(libwebpVersion)).
Quality(quality).