mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-04 18:33:36 +02:00
NewProcessingOptions without hacks
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@@ -109,50 +108,42 @@ type ProcessingOptions struct {
|
|||||||
defaultQuality int
|
defaultQuality int
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
_newProcessingOptions ProcessingOptions
|
|
||||||
newProcessingOptionsOnce sync.Once
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewProcessingOptions() *ProcessingOptions {
|
func NewProcessingOptions() *ProcessingOptions {
|
||||||
newProcessingOptionsOnce.Do(func() {
|
po := ProcessingOptions{
|
||||||
_newProcessingOptions = ProcessingOptions{
|
ResizingType: ResizeFit,
|
||||||
ResizingType: ResizeFit,
|
Width: 0,
|
||||||
Width: 0,
|
Height: 0,
|
||||||
Height: 0,
|
ZoomWidth: 1,
|
||||||
ZoomWidth: 1,
|
ZoomHeight: 1,
|
||||||
ZoomHeight: 1,
|
Gravity: GravityOptions{Type: GravityCenter},
|
||||||
Gravity: GravityOptions{Type: GravityCenter},
|
Enlarge: false,
|
||||||
Enlarge: false,
|
Extend: ExtendOptions{Enabled: false, Gravity: GravityOptions{Type: GravityCenter}},
|
||||||
Extend: ExtendOptions{Enabled: false, Gravity: GravityOptions{Type: GravityCenter}},
|
Padding: PaddingOptions{Enabled: false},
|
||||||
Padding: PaddingOptions{Enabled: false},
|
Trim: TrimOptions{Enabled: false, Threshold: 10, Smart: true},
|
||||||
Trim: TrimOptions{Enabled: false, Threshold: 10, Smart: true},
|
Rotate: 0,
|
||||||
Rotate: 0,
|
Quality: 0,
|
||||||
Quality: 0,
|
MaxBytes: 0,
|
||||||
MaxBytes: 0,
|
Format: imagetype.Unknown,
|
||||||
Format: imagetype.Unknown,
|
Background: vips.Color{R: 255, G: 255, B: 255},
|
||||||
Background: vips.Color{R: 255, G: 255, B: 255},
|
Blur: 0,
|
||||||
Blur: 0,
|
Sharpen: 0,
|
||||||
Sharpen: 0,
|
Dpr: 1,
|
||||||
Dpr: 1,
|
Watermark: WatermarkOptions{Opacity: 1, Replicate: false, Gravity: GravityOptions{Type: GravityCenter}},
|
||||||
Watermark: WatermarkOptions{Opacity: 1, Replicate: false, Gravity: GravityOptions{Type: GravityCenter}},
|
StripMetadata: config.StripMetadata,
|
||||||
StripMetadata: config.StripMetadata,
|
KeepCopyright: config.KeepCopyright,
|
||||||
KeepCopyright: config.KeepCopyright,
|
StripColorProfile: config.StripColorProfile,
|
||||||
StripColorProfile: config.StripColorProfile,
|
AutoRotate: config.AutoRotate,
|
||||||
AutoRotate: config.AutoRotate,
|
EnforceThumbnail: config.EnforceThumbnail,
|
||||||
EnforceThumbnail: config.EnforceThumbnail,
|
ReturnAttachment: config.ReturnAttachment,
|
||||||
ReturnAttachment: config.ReturnAttachment,
|
|
||||||
|
|
||||||
// Basically, we need this to update ETag when `IMGPROXY_QUALITY` is changed
|
SkipProcessingFormats: append([]imagetype.Type(nil), config.SkipProcessingFormats...),
|
||||||
defaultQuality: config.Quality,
|
UsedPresets: make([]string, 0, len(config.Presets)),
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
po := _newProcessingOptions
|
// Basically, we need this to update ETag when `IMGPROXY_QUALITY` is changed
|
||||||
po.SkipProcessingFormats = append([]imagetype.Type(nil), config.SkipProcessingFormats...)
|
defaultQuality: config.Quality,
|
||||||
po.UsedPresets = make([]string, 0, len(config.Presets))
|
}
|
||||||
|
|
||||||
po.FormatQuality = make(map[imagetype.Type]int)
|
po.FormatQuality = make(map[imagetype.Type]int, len(config.FormatQuality))
|
||||||
for k, v := range config.FormatQuality {
|
for k, v := range config.FormatQuality {
|
||||||
po.FormatQuality[k] = v
|
po.FormatQuality[k] = v
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user