1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-06-27 22:38:33 +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 EnforceWebp bool
EnableClientHints bool EnableClientHints bool
DisableShrinkOnLoad bool
Keys []securityKey Keys []securityKey
Salts []securityKey Salts []securityKey
AllowInsecure bool AllowInsecure bool
@ -267,6 +269,8 @@ func init() {
boolEnvConfig(&conf.EnforceWebp, "IMGPROXY_ENFORCE_WEBP") boolEnvConfig(&conf.EnforceWebp, "IMGPROXY_ENFORCE_WEBP")
boolEnvConfig(&conf.EnableClientHints, "IMGPROXY_ENABLE_CLIENT_HINTS") boolEnvConfig(&conf.EnableClientHints, "IMGPROXY_ENABLE_CLIENT_HINTS")
boolEnvConfig(&conf.DisableShrinkOnLoad, "IMGPROXY_DISABLE_SHRINK_ON_LOAD")
hexEnvConfig(&conf.Keys, "IMGPROXY_KEY") hexEnvConfig(&conf.Keys, "IMGPROXY_KEY")
hexEnvConfig(&conf.Salts, "IMGPROXY_SALT") hexEnvConfig(&conf.Salts, "IMGPROXY_SALT")
intEnvConfig(&conf.SignatureSize, "IMGPROXY_SIGNATURE_SIZE") 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 ### 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_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) scale := calcScale(imgWidth, imgHeight, po, imgtype)
if scale != 1 { if scale != 1 && data != nil {
if imgtype == imageTypeSVG && data != nil { if imgtype == imageTypeSVG {
// Load SVG with desired scale // Load SVG with desired scale
if tmp, err := vipsLoadImage(data, imgtype, 1, scale, false); err == nil { if tmp, err := vipsLoadImage(data, imgtype, 1, scale, false); err == nil {
C.swap_and_clear(img, tmp) C.swap_and_clear(img, tmp)
@ -294,9 +294,8 @@ func transformImage(ctx context.Context, img **C.VipsImage, data []byte, po *pro
} }
scale = 1 scale = 1
} else { } else if !conf.DisableShrinkOnLoad && scale < 1.0 {
// Do some shrink-on-load // Do some shrink-on-load
if scale < 1.0 && data != nil {
if shrink := calcShink(scale, imgtype); shrink != 1 { if shrink := calcShink(scale, imgtype); shrink != 1 {
if tmp, err := vipsLoadImage(data, imgtype, shrink, 1.0, false); err == nil { if tmp, err := vipsLoadImage(data, imgtype, shrink, 1.0, false); err == nil {
C.swap_and_clear(img, tmp) C.swap_and_clear(img, tmp)
@ -308,7 +307,6 @@ func transformImage(ctx context.Context, img **C.VipsImage, data []byte, po *pro
} }
} }
} }
}
if err = vipsRad2Float(img); err != nil { if err = vipsRad2Float(img); err != nil {
return err return err