1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-02-02 11:34:20 +02:00

Add IMGPROXY_DISABLE_SHRINK_ON_LOAD config

This commit is contained in:
DarthSim 2019-04-01 21:30:53 +06:00
parent 550b9edb20
commit c864f801d0
3 changed files with 15 additions and 12 deletions

View File

@ -152,6 +152,8 @@ type config struct {
EnforceWebp bool
EnableClientHints bool
DisableShrinkOnLoad bool
Keys []securityKey
Salts []securityKey
AllowInsecure bool
@ -267,6 +269,8 @@ func init() {
boolEnvConfig(&conf.EnforceWebp, "IMGPROXY_ENFORCE_WEBP")
boolEnvConfig(&conf.EnableClientHints, "IMGPROXY_ENABLE_CLIENT_HINTS")
boolEnvConfig(&conf.DisableShrinkOnLoad, "IMGPROXY_DISABLE_SHRINK_ON_LOAD")
hexEnvConfig(&conf.Keys, "IMGPROXY_KEY")
hexEnvConfig(&conf.Salts, "IMGPROXY_SALT")
intEnvConfig(&conf.SignatureSize, "IMGPROXY_SIGNATURE_SIZE")

View File

@ -200,3 +200,4 @@ imgproxy can send logs to syslog, but this feature is disabled by default. To en
### Miscellaneous
* `IMGPROXY_BASE_URL`: base URL prefix that will be added to every requested image URL. For example, if the base URL is `http://example.com/images` and `/path/to/image.png` is requested, imgproxy will download the source image from `http://example.com/images/path/to/image.png`. Default: blank.
* `IMGPROXY_DISABLE_SHRINK_ON_LOAD`: when `true`, disables shrink-on-load for JPEG and WebP. Allows to process the whole image in linear colorspace but dramatically slows down resizing and increases memory usage when working with large images.

View File

@ -284,8 +284,8 @@ func transformImage(ctx context.Context, img **C.VipsImage, data []byte, po *pro
scale := calcScale(imgWidth, imgHeight, po, imgtype)
if scale != 1 {
if imgtype == imageTypeSVG && data != nil {
if scale != 1 && data != nil {
if imgtype == imageTypeSVG {
// Load SVG with desired scale
if tmp, err := vipsLoadImage(data, imgtype, 1, scale, false); err == nil {
C.swap_and_clear(img, tmp)
@ -294,18 +294,16 @@ func transformImage(ctx context.Context, img **C.VipsImage, data []byte, po *pro
}
scale = 1
} else {
} else if !conf.DisableShrinkOnLoad && scale < 1.0 {
// Do some shrink-on-load
if scale < 1.0 && data != nil {
if shrink := calcShink(scale, imgtype); shrink != 1 {
if tmp, err := vipsLoadImage(data, imgtype, shrink, 1.0, false); err == nil {
C.swap_and_clear(img, tmp)
} else {
return err
}
scale = scale * float64(shrink)
if shrink := calcShink(scale, imgtype); shrink != 1 {
if tmp, err := vipsLoadImage(data, imgtype, shrink, 1.0, false); err == nil {
C.swap_and_clear(img, tmp)
} else {
return err
}
scale = scale * float64(shrink)
}
}
}