You've already forked imgproxy
mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-11-27 22:48:53 +02:00
Simplify WebP preset config
This commit is contained in:
37
vips/vips.go
37
vips/vips.go
@@ -33,30 +33,10 @@ import (
|
||||
"github.com/imgproxy/imgproxy/v3/metrics/prometheus"
|
||||
)
|
||||
|
||||
const (
|
||||
webpPresetDefault = "default"
|
||||
webpPresetPhoto = "photo"
|
||||
webpPresetPicture = "picture"
|
||||
webpPresetDrawing = "drawing"
|
||||
webpPresetIcon = "icon"
|
||||
webpPresetText = "text"
|
||||
)
|
||||
|
||||
type Image struct {
|
||||
VipsImage *C.VipsImage
|
||||
}
|
||||
|
||||
var (
|
||||
cWebpPreset = map[string]C.VipsForeignWebpPreset{
|
||||
webpPresetDefault: C.VIPS_FOREIGN_WEBP_PRESET_DEFAULT,
|
||||
webpPresetPhoto: C.VIPS_FOREIGN_WEBP_PRESET_PHOTO,
|
||||
webpPresetPicture: C.VIPS_FOREIGN_WEBP_PRESET_PICTURE,
|
||||
webpPresetDrawing: C.VIPS_FOREIGN_WEBP_PRESET_DRAWING,
|
||||
webpPresetIcon: C.VIPS_FOREIGN_WEBP_PRESET_ICON,
|
||||
webpPresetText: C.VIPS_FOREIGN_WEBP_PRESET_TEXT,
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
typeSupportLoad sync.Map
|
||||
typeSupportSave sync.Map
|
||||
@@ -127,10 +107,19 @@ func Init() error {
|
||||
vipsConf.PngUnlimited = gbool(config.PngUnlimited)
|
||||
vipsConf.SvgUnlimited = gbool(config.SvgUnlimited)
|
||||
|
||||
if p, ok := cWebpPreset[config.WebpPreset]; ok {
|
||||
vipsConf.WebpPreset = p
|
||||
} else {
|
||||
return newVipsErrorf("invalid libwebp preset: %s", config.WebpPreset)
|
||||
switch config.WebpPreset {
|
||||
case config.WebpPresetPhoto:
|
||||
vipsConf.WebpPreset = C.VIPS_FOREIGN_WEBP_PRESET_PHOTO
|
||||
case config.WebpPresetPicture:
|
||||
vipsConf.WebpPreset = C.VIPS_FOREIGN_WEBP_PRESET_PICTURE
|
||||
case config.WebpPresetDrawing:
|
||||
vipsConf.WebpPreset = C.VIPS_FOREIGN_WEBP_PRESET_DRAWING
|
||||
case config.WebpPresetIcon:
|
||||
vipsConf.WebpPreset = C.VIPS_FOREIGN_WEBP_PRESET_ICON
|
||||
case config.WebpPresetText:
|
||||
vipsConf.WebpPreset = C.VIPS_FOREIGN_WEBP_PRESET_TEXT
|
||||
default:
|
||||
vipsConf.WebpPreset = C.VIPS_FOREIGN_WEBP_PRESET_DEFAULT
|
||||
}
|
||||
|
||||
prometheus.AddGaugeFunc(
|
||||
|
||||
Reference in New Issue
Block a user