mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-03-22 20:21:28 +02:00
Apply default preset when defined
This commit is contained in:
parent
1569f9be20
commit
419f01028e
@ -80,19 +80,6 @@ type processingOptions struct {
|
||||
Sharpen float32
|
||||
}
|
||||
|
||||
func defaultProcessingOptions() processingOptions {
|
||||
return processingOptions{
|
||||
Resize: resizeFit,
|
||||
Width: 0,
|
||||
Height: 0,
|
||||
Gravity: gravityCenter,
|
||||
Enlarge: false,
|
||||
Format: imageTypeJPEG,
|
||||
Blur: 0,
|
||||
Sharpen: 0,
|
||||
}
|
||||
}
|
||||
|
||||
func decodeURL(parts []string) (string, imageType, error) {
|
||||
var imgType imageType = imageTypeJPEG
|
||||
|
||||
@ -339,8 +326,32 @@ func parseURLOptions(opts []string) (urlOptions, []string) {
|
||||
return parsed, rest
|
||||
}
|
||||
|
||||
func defaultProcessingOptions() (processingOptions, error) {
|
||||
var err error
|
||||
|
||||
po := processingOptions{
|
||||
Resize: resizeFit,
|
||||
Width: 0,
|
||||
Height: 0,
|
||||
Gravity: gravityCenter,
|
||||
Enlarge: false,
|
||||
Format: imageTypeJPEG,
|
||||
Blur: 0,
|
||||
Sharpen: 0,
|
||||
}
|
||||
|
||||
if _, ok := conf.Presets["default"]; ok {
|
||||
err = applyPresetOption(&po, []string{"default"})
|
||||
}
|
||||
|
||||
return po, err
|
||||
}
|
||||
|
||||
func parsePathAdvanced(parts []string) (string, processingOptions, error) {
|
||||
po := defaultProcessingOptions()
|
||||
po, err := defaultProcessingOptions()
|
||||
if err != nil {
|
||||
return "", po, err
|
||||
}
|
||||
|
||||
options, urlParts := parseURLOptions(parts)
|
||||
|
||||
@ -363,11 +374,15 @@ func parsePathAdvanced(parts []string) (string, processingOptions, error) {
|
||||
}
|
||||
|
||||
func parsePathSimple(parts []string) (string, processingOptions, error) {
|
||||
var po processingOptions
|
||||
var err error
|
||||
|
||||
if len(parts) < 6 {
|
||||
return "", po, errors.New("Invalid path")
|
||||
return "", processingOptions{}, errors.New("Invalid path")
|
||||
}
|
||||
|
||||
po, err := defaultProcessingOptions()
|
||||
if err != nil {
|
||||
return "", po, err
|
||||
}
|
||||
|
||||
po.Resize = resizeTypes[parts[0]]
|
||||
|
Loading…
x
Reference in New Issue
Block a user