Skip to content

Commit

Permalink
support vips avif speed (#463)
Browse files Browse the repository at this point in the history
* support vips avif speed

* support vips avif speed, add option test
  • Loading branch information
liudongmiao authored Aug 9, 2024
1 parent 22caa38 commit 82e9a05
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -809,4 +809,6 @@ Usage of imagor:
VIPS max image resolution
-vips-mozjpeg
VIPS enable maximum compression with MozJPEG. Requires mozjpeg to be installed
-vips-avif-speed int
VIPS avif speed, the lowest is at 0 and the fastest is at 9 (Default 5).
```
3 changes: 3 additions & 0 deletions config/vipsconfig/vipsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func WithVips(fs *flag.FlagSet, cb func() (*zap.Logger, bool)) imagor.Option {
"VIPS max image resolution")
vipsMozJPEG = fs.Bool("vips-mozjpeg", false,
"VIPS enable maximum compression with MozJPEG. Requires mozjpeg to be installed")
vipsAvifSpeed = fs.Int("vips-avif-speed", 5,
"VIPS avif speed, the lowest is at 0 and the fastest is at 9 (Default 5).")

logger, isDebug = cb()
)
Expand All @@ -51,6 +53,7 @@ func WithVips(fs *flag.FlagSet, cb func() (*zap.Logger, bool)) imagor.Option {
vips.WithMaxHeight(*vipsMaxHeight),
vips.WithMaxResolution(*vipsMaxResolution),
vips.WithMozJPEG(*vipsMozJPEG),
vips.WithAvifSpeed(*vipsAvifSpeed),
vips.WithLogger(logger),
vips.WithDebug(isDebug),
),
Expand Down
9 changes: 9 additions & 0 deletions vips/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ func WithMozJPEG(enabled bool) Option {
}
}

// WithAvifSpeed with avif speed option
func WithAvifSpeed(avifSpeed int) Option {
return func(v *Processor) {
if avifSpeed >= 0 && avifSpeed <= 9 {
v.AvifSpeed = avifSpeed
}
}
}

// WithMaxFilterOps with maximum number of filter operations option
func WithMaxFilterOps(num int) Option {
return func(v *Processor) {
Expand Down
2 changes: 2 additions & 0 deletions vips/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestWithOption(t *testing.T) {
WithMaxHeight(998),
WithMaxResolution(1666667),
WithMozJPEG(true),
WithAvifSpeed(9),
WithDebug(true),
WithMaxAnimationFrames(3),
WithDisableFilters("rgb", "fill, watermark"),
Expand All @@ -37,6 +38,7 @@ func TestWithOption(t *testing.T) {
assert.Equal(t, 1666667, v.MaxResolution)
assert.Equal(t, 3, v.MaxAnimationFrames)
assert.Equal(t, true, v.MozJPEG)
assert.Equal(t, 9, v.AvifSpeed)
assert.Equal(t, []string{"rgb", "fill", "watermark"}, v.DisableFilters)

})
Expand Down
1 change: 1 addition & 0 deletions vips/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ func (v *Processor) export(
if quality > 0 {
opts.Quality = quality
}
opts.Speed = v.AvifSpeed
return image.ExportAvif(opts)
case ImageTypeHEIF:
opts := NewHeifExportParams()
Expand Down
1 change: 1 addition & 0 deletions vips/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Processor struct {
MaxResolution int
MaxAnimationFrames int
MozJPEG bool
AvifSpeed int
Debug bool

disableFilters map[string]bool
Expand Down

0 comments on commit 82e9a05

Please sign in to comment.