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