mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-08 03:00:27 +08:00
WebP转换质量转移到WebP策略配置
This commit is contained in:
@@ -67,6 +67,7 @@ type HTTPWriter struct {
|
|||||||
// WebP
|
// WebP
|
||||||
webpIsEncoding bool
|
webpIsEncoding bool
|
||||||
webpOriginContentType string
|
webpOriginContentType string
|
||||||
|
webpQuality int
|
||||||
|
|
||||||
// Compression
|
// Compression
|
||||||
compressionConfig *serverconfigs.HTTPCompressionConfig
|
compressionConfig *serverconfigs.HTTPCompressionConfig
|
||||||
@@ -470,8 +471,8 @@ func (this *HTTPWriter) PrepareCache(resp *http.Response, size int64) {
|
|||||||
contentTypeWritten = true
|
contentTypeWritten = true
|
||||||
}
|
}
|
||||||
|
|
||||||
err := cacheWriter.WriteAt(start, data)
|
writeErr := cacheWriter.WriteAt(start, data)
|
||||||
if err != nil {
|
if writeErr != nil {
|
||||||
hasError = true
|
hasError = true
|
||||||
this.cacheIsFinished = false
|
this.cacheIsFinished = false
|
||||||
}
|
}
|
||||||
@@ -518,6 +519,7 @@ func (this *HTTPWriter) PrepareWebP(resp *http.Response, size int64) {
|
|||||||
if policy.RequireCache && this.req.cacheRef == nil {
|
if policy.RequireCache && this.req.cacheRef == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
this.webpQuality = policy.Quality
|
||||||
|
|
||||||
// 限制最小和最大尺寸
|
// 限制最小和最大尺寸
|
||||||
// TODO 需要将reader修改为LimitReader
|
// TODO 需要将reader修改为LimitReader
|
||||||
@@ -1092,9 +1094,17 @@ func (this *HTTPWriter) finishWebP() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var f = types.Float32(this.req.web.WebP.Quality)
|
var f = types.Float32(this.webpQuality)
|
||||||
if f > 100 {
|
if f <= 0 || f > 100 {
|
||||||
f = 100
|
if this.size > (8<<20) || this.size <= 0 {
|
||||||
|
f = 30
|
||||||
|
} else if this.size > (1 << 20) {
|
||||||
|
f = 50
|
||||||
|
} else if this.size > (128 << 10) {
|
||||||
|
f = 60
|
||||||
|
} else {
|
||||||
|
f = 75
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if imageData != nil {
|
if imageData != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user