mirror of
https://github.com/coalaura/ffwebp.git
synced 2025-07-17 13:54:36 +00:00
thumbnail parameter
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
||||
"github.com/coalaura/ffwebp/internal/codec"
|
||||
"github.com/coalaura/ffwebp/internal/logx"
|
||||
"github.com/coalaura/ffwebp/internal/opts"
|
||||
"github.com/nfnt/resize"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
@ -46,6 +47,11 @@ func main() {
|
||||
Aliases: []string{"l"},
|
||||
Usage: "force lossless mode (overrides --quality)",
|
||||
},
|
||||
&cli.UintFlag{
|
||||
Name: "thumbnail",
|
||||
Aliases: []string{"t"},
|
||||
Usage: "create a thumbnail no wider/taller than the specified size",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "silent",
|
||||
Aliases: []string{"s"},
|
||||
@ -149,6 +155,14 @@ func run(_ context.Context, cmd *cli.Command) error {
|
||||
|
||||
logx.Printf("decoded image: %dx%d %s in %s\n", img.Bounds().Dx(), img.Bounds().Dy(), colorModel(img), time.Since(t0).Truncate(time.Millisecond))
|
||||
|
||||
if thumbnail := cmd.Uint("thumbnail"); thumbnail > 0 {
|
||||
t2 := time.Now()
|
||||
|
||||
img = resize.Thumbnail(thumbnail, thumbnail, img, resize.Lanczos3)
|
||||
|
||||
logx.Printf("resized image: %dx%d in %s\n", img.Bounds().Dx(), img.Bounds().Dy(), time.Since(t2).Truncate(time.Millisecond))
|
||||
}
|
||||
|
||||
t1 := time.Now()
|
||||
|
||||
err = oCodec.Encode(writer, img, common)
|
||||
|
1
go.mod
1
go.mod
@ -6,6 +6,7 @@ require github.com/urfave/cli/v3 v3.3.8
|
||||
|
||||
require (
|
||||
github.com/gen2brain/webp v0.5.5
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8
|
||||
)
|
||||
|
||||
|
2
go.sum
2
go.sum
@ -4,6 +4,8 @@ github.com/ebitengine/purego v0.8.3 h1:K+0AjQp63JEZTEMZiwsI9g0+hAMNohwUOtY0RPGex
|
||||
github.com/ebitengine/purego v0.8.3/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
|
||||
github.com/gen2brain/webp v0.5.5 h1:MvQR75yIPU/9nSqYT5h13k4URaJK3gf9tgz/ksRbyEg=
|
||||
github.com/gen2brain/webp v0.5.5/go.mod h1:xOSMzp4aROt2KFW++9qcK/RBTOVC2S9tJG66ip/9Oc0=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
|
Reference in New Issue
Block a user