mirror of
https://github.com/woodchen-ink/webp_server_go.git
synced 2025-07-18 05:32:02 +08:00
parent
24b96a901b
commit
b988668893
@ -58,7 +58,7 @@ var (
|
||||
ProxyMode bool
|
||||
Prefetch bool
|
||||
Config jsonFile
|
||||
Version = "0.9.5"
|
||||
Version = "0.9.6"
|
||||
WriteLock = cache.New(5*time.Minute, 10*time.Minute)
|
||||
)
|
||||
|
||||
|
@ -228,18 +228,9 @@ func webpEncoder(p1, p2 string, extraParams config.ExtraParams) error {
|
||||
Lossless: true,
|
||||
StripMetadata: true,
|
||||
})
|
||||
// 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,
|
||||
})
|
||||
}
|
||||
}
|
||||
// Lossless mode will not encount problems as below, because in libvips as code below
|
||||
// config.method = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
// use_lossless_preset = 0; // disable -z option
|
||||
} else {
|
||||
buf, _, err = img.ExportWebp(&vips.WebpExportParams{
|
||||
Quality: quality,
|
||||
@ -250,13 +241,20 @@ func webpEncoder(p1, p2 string, extraParams config.ExtraParams) error {
|
||||
// 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,
|
||||
})
|
||||
log.Warnf("Can't encode source image to WebP with default ReductionEffort")
|
||||
// Loop through ReductionEffort from 1 to 6
|
||||
for i := 1; i <= 6; i++ {
|
||||
log.Warnf("Retry using ReductionEffort: %d", i)
|
||||
buf, _, err = img.ExportWebp(&vips.WebpExportParams{
|
||||
Quality: quality,
|
||||
Lossless: false,
|
||||
StripMetadata: true,
|
||||
ReductionEffort: i,
|
||||
})
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user