diff --git a/options.go b/options.go index c5676210..99657556 100644 --- a/options.go +++ b/options.go @@ -188,39 +188,40 @@ type Sharpen struct { // Options represents the supported image transformation options. type Options struct { - Height int - Width int - AreaHeight int - AreaWidth int - Top int - Left int - Quality int - Compression int - Zoom int - Crop bool - SmartCrop bool // Deprecated, use: bimg.Options.Gravity = bimg.GravitySmart - Enlarge bool - Embed bool - Flip bool - Flop bool - Force bool - NoAutoRotate bool - NoProfile bool - Interlace bool - StripMetadata bool - Trim bool - Lossless bool - Extend Extend - Rotate Angle - Background Color - Gravity Gravity - Watermark Watermark - WatermarkImage WatermarkImage - Type ImageType - Interpolator Interpolator - Interpretation Interpretation - GaussianBlur GaussianBlur - Sharpen Sharpen - Threshold float64 - OutputICC string + Height int + Width int + AreaHeight int + AreaWidth int + Top int + Left int + Quality int + Compression int + Zoom int + Crop bool + SmartCrop bool // Deprecated, use: bimg.Options.Gravity = bimg.GravitySmart + Enlarge bool + Embed bool + Flip bool + Flop bool + Force bool + NoAutoRotate bool + NoProfile bool + Interlace bool + StripMetadata bool + Trim bool + Lossless bool + Extend Extend + Rotate Angle + Background Color + Gravity Gravity + Watermark Watermark + WatermarkImage WatermarkImage + Type ImageType + Interpolator Interpolator + Interpretation Interpretation + GaussianBlur GaussianBlur + Sharpen Sharpen + Threshold float64 + OutputICC string + IgnoreShrinkOnLoad bool } diff --git a/resizer.go b/resizer.go index a8e998c7..6bad93d0 100644 --- a/resizer.go +++ b/resizer.go @@ -70,21 +70,23 @@ func resizer(buf []byte, o Options) ([]byte, error) { } } - // Try to use libjpeg/libwebp shrink-on-load - supportsShrinkOnLoad := imageType == WEBP && VipsMajorVersion >= 8 && VipsMinorVersion >= 3 - supportsShrinkOnLoad = supportsShrinkOnLoad || imageType == JPEG - if supportsShrinkOnLoad && shrink >= 2 { - tmpImage, factor, err := shrinkOnLoad(buf, image, imageType, factor, shrink) - if err != nil { - return nil, err - } - image = tmpImage - factor = math.Max(factor, 1.0) - shrink = int(math.Floor(factor)) - residual = float64(shrink) / factor + if !o.IgnoreShrinkOnLoad { + // Try to use libjpeg/libwebp shrink-on-load + supportsShrinkOnLoad := imageType == WEBP && VipsMajorVersion >= 8 && VipsMinorVersion >= 3 + supportsShrinkOnLoad = supportsShrinkOnLoad || imageType == JPEG + if supportsShrinkOnLoad && shrink >= 2 { + tmpImage, factor, err := shrinkOnLoad(buf, image, imageType, factor, shrink) + if err != nil { + return nil, err + } + + image = tmpImage + factor = math.Max(factor, 1.0) + shrink = int(math.Floor(factor)) + residual = float64(shrink) / factor + } } - // Zoom image, if necessary image, err = zoomImage(image, o.Zoom) if err != nil {