Add image type check to calcShrink

This commit is contained in:
DarthSim
2018-09-07 22:05:28 +06:00
parent 9f0a2a4939
commit 9efba7bf55

View File

@@ -166,6 +166,7 @@ func calcShink(scale float64, imgtype imageType) int {
return shrink return shrink
} }
if imgtype != imageTypeWEBP {
switch { switch {
case shrink >= 16: case shrink >= 16:
return 8 return 8
@@ -174,6 +175,7 @@ func calcShink(scale float64, imgtype imageType) int {
case shrink >= 4: case shrink >= 4:
return 2 return 2
} }
}
return 1 return 1
} }
@@ -235,8 +237,7 @@ func processImage(data []byte, imgtype imageType, po processingOptions, t *timer
// Do some shrink-on-load // Do some shrink-on-load
if scale < 1.0 { if scale < 1.0 {
if imgtype == imageTypeJPEG || imgtype == imageTypeWEBP { if shrink := calcShink(scale, imgtype); shrink != 1 {
shrink := calcShink(scale, imgtype)
scale = scale * float64(shrink) scale = scale * float64(shrink)
if tmp, e := vipsLoadImage(data, imgtype, shrink); e == nil { if tmp, e := vipsLoadImage(data, imgtype, shrink); e == nil {