1
0
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:
DarthSim
2025-06-30 18:28:31 +03:00
parent 4d684fab0a
commit 92a281f834
4 changed files with 71 additions and 27 deletions

View File

@@ -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(