Skip to content

Commit

Permalink
the same for webp
Browse files Browse the repository at this point in the history
  • Loading branch information
takutakahashi committed Feb 20, 2024
1 parent 15f3f16 commit 71746b8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion webp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"net/url"
"os"
"os/exec"

"github.com/disintegration/imaging"
)

func doWebp(req *http.Request) (*http.Response, error) {
Expand Down Expand Up @@ -50,10 +52,15 @@ func convWebp(src io.Reader, params []string) (*bytes.Buffer, error) {
defer f.Close()
defer os.Remove(f.Name())

_, err = io.Copy(f, src)
img, err := imaging.Decode(src, imaging.AutoOrientation(true))
if err != nil {
return nil, err
}

if err := imaging.Encode(f, img, imaging.JPEG); err != nil {
return nil, err
}

params = append(params, "-quiet", "-mt", "-jpeg_like", f.Name(), "-o", "-")
out, err := exec.Command("cwebp", params...).Output()
if err != nil {
Expand Down

0 comments on commit 71746b8

Please sign in to comment.