mirror of
https://github.com/woodchen-ink/webp_server_go.git
synced 2025-07-18 13:42:02 +08:00
ReductionEffort to 0 (#254)
This commit is contained in:
parent
a7b5992662
commit
24b96a901b
@ -58,7 +58,7 @@ var (
|
|||||||
ProxyMode bool
|
ProxyMode bool
|
||||||
Prefetch bool
|
Prefetch bool
|
||||||
Config jsonFile
|
Config jsonFile
|
||||||
Version = "0.9.4"
|
Version = "0.9.5"
|
||||||
WriteLock = cache.New(5*time.Minute, 10*time.Minute)
|
WriteLock = cache.New(5*time.Minute, 10*time.Minute)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"webp_server_go/config"
|
"webp_server_go/config"
|
||||||
"webp_server_go/helper"
|
"webp_server_go/helper"
|
||||||
@ -224,17 +225,40 @@ func webpEncoder(p1, p2 string, extraParams config.ExtraParams) error {
|
|||||||
// If quality >= 100, we use lossless mode
|
// If quality >= 100, we use lossless mode
|
||||||
if quality >= 100 {
|
if quality >= 100 {
|
||||||
buf, _, err = img.ExportWebp(&vips.WebpExportParams{
|
buf, _, err = img.ExportWebp(&vips.WebpExportParams{
|
||||||
Lossless: true,
|
Lossless: true,
|
||||||
StripMetadata: true,
|
StripMetadata: true,
|
||||||
ReductionEffort: 4,
|
|
||||||
})
|
})
|
||||||
|
// If some special images cannot encode with default ReductionEffort(0), then try with 4
|
||||||
|
// Example: https://github.com/webp-sh/webp_server_go/issues/234
|
||||||
|
if err != nil {
|
||||||
|
if strings.Contains(err.Error(), "unable to encode") {
|
||||||
|
log.Warnf("Can't encode source image to WebP with default ReductionEffort, retry using ReductionEffort:4")
|
||||||
|
buf, _, err = img.ExportWebp(&vips.WebpExportParams{
|
||||||
|
Lossless: true,
|
||||||
|
StripMetadata: true,
|
||||||
|
ReductionEffort: 4,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
buf, _, err = img.ExportWebp(&vips.WebpExportParams{
|
buf, _, err = img.ExportWebp(&vips.WebpExportParams{
|
||||||
Quality: quality,
|
Quality: quality,
|
||||||
Lossless: false,
|
Lossless: false,
|
||||||
StripMetadata: true,
|
StripMetadata: true,
|
||||||
ReductionEffort: 4,
|
|
||||||
})
|
})
|
||||||
|
// If some special images cannot encode with default ReductionEffort(0), then try with 4
|
||||||
|
// Example: https://github.com/webp-sh/webp_server_go/issues/234
|
||||||
|
if err != nil {
|
||||||
|
if strings.Contains(err.Error(), "unable to encode") {
|
||||||
|
log.Warnf("Can't encode source image to WebP with default ReductionEffort, retry using ReductionEffort:4")
|
||||||
|
buf, _, err = img.ExportWebp(&vips.WebpExportParams{
|
||||||
|
Quality: quality,
|
||||||
|
Lossless: false,
|
||||||
|
StripMetadata: true,
|
||||||
|
ReductionEffort: 4,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -17,8 +17,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var app = fiber.New(fiber.Config{
|
var app = fiber.New(fiber.Config{
|
||||||
ServerHeader: "Webp Server Go",
|
ServerHeader: "WebP Server Go",
|
||||||
AppName: "Webp Server Go",
|
AppName: "WebP Server Go",
|
||||||
DisableStartupMessage: true,
|
DisableStartupMessage: true,
|
||||||
ProxyHeader: "X-Real-IP",
|
ProxyHeader: "X-Real-IP",
|
||||||
})
|
})
|
||||||
@ -43,7 +43,7 @@ func setupLogger() {
|
|||||||
TimeFormat: config.TimeDateFormat,
|
TimeFormat: config.TimeDateFormat,
|
||||||
}))
|
}))
|
||||||
app.Use(recover.New(recover.Config{}))
|
app.Use(recover.New(recover.Config{}))
|
||||||
log.Infoln("fiber ready.")
|
log.Infoln("WebP Server Go ready.")
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user