diff --git a/CHANGELOG.md b/CHANGELOG.md index 661398e7..98bad6e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,11 @@ # Changelog +## [Unreleased] +### Fix +- Fix HEIC/AVIF dimension limit handling. + ## [3.24.1] - 2024-04-30 -## Fix +### Fix - Fix the default `IMGPROXY_WORKERS` value when cgroup limits are applied. ## [3.24.0] - 2024-04-29 diff --git a/processing/fix_size.go b/processing/fix_size.go index 683ebbd8..c8ccf17c 100644 --- a/processing/fix_size.go +++ b/processing/fix_size.go @@ -14,6 +14,7 @@ import ( const ( // https://chromium.googlesource.com/webm/libwebp/+/refs/heads/master/src/webp/encode.h#529 webpMaxDimension = 16383.0 + heifMaxDimension = 16384.0 gifMaxDimension = 65535.0 icoMaxDimension = 256.0 ) @@ -35,6 +36,23 @@ func fixWebpSize(img *vips.Image) error { return nil } +func fixHeifSize(img *vips.Image) error { + heifLimitShrink := float64(imath.Max(img.Width(), img.Height())) / heifMaxDimension + + if heifLimitShrink <= 1.0 { + return nil + } + + scale := 1.0 / heifLimitShrink + if err := img.Resize(scale, scale); err != nil { + return err + } + + log.Warningf("AVIF/HEIC dimension size is limited to %d. The image is rescaled to %dx%d", int(heifMaxDimension), img.Width(), img.Height()) + + return nil +} + func fixGifSize(img *vips.Image) error { gifMaxResolution := float64(vips.GifResolutionLimit()) gifResLimitShrink := float64(img.Width()*img.Height()) / gifMaxResolution @@ -77,6 +95,8 @@ func fixSize(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptio switch po.Format { case imagetype.WEBP: return fixWebpSize(img) + case imagetype.AVIF, imagetype.HEIC: + return fixHeifSize(img) case imagetype.GIF: return fixGifSize(img) case imagetype.ICO: