From b8f5d4302db406ab091ac051078b640bdb073cbe Mon Sep 17 00:00:00 2001 From: DarthSim Date: Mon, 28 Sep 2020 15:57:39 +0600 Subject: [PATCH] Fix DPR --- CHANGELOG.md | 3 +++ process.go | 21 +++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78832736..0e606504 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ ### Added - AVIF support. +### Fix +- Fix `dpr` option. + ## [2.15.0] - 2020-09-03 ### Added - Ability to skip processing of some formats. See [Skip processing](https://docs.imgproxy.net/#/configuration?id=skip-processing). diff --git a/process.go b/process.go index 95844036..844fca61 100644 --- a/process.go +++ b/process.go @@ -353,11 +353,14 @@ func transformImage(ctx context.Context, img *vipsImage, data []byte, po *proces // Update scale after scale-on-load newWidth, newHeight, _, _ := extractMeta(img) - - widthToScale = scaleInt(widthToScale, float64(newWidth)/float64(srcWidth)) - heightToScale = scaleInt(heightToScale, float64(newHeight)/float64(srcHeight)) - - scale = calcScale(widthToScale, heightToScale, po, imgtype) + if srcWidth > srcHeight { + scale = float64(srcWidth) * scale / float64(newWidth) + } else { + scale = float64(srcHeight) * scale / float64(newHeight) + } + if srcWidth == scaleInt(srcWidth, scale) && srcHeight == scaleInt(srcHeight, scale) { + scale = 1.0 + } } if err = img.Rad2Float(); err != nil { @@ -365,7 +368,7 @@ func transformImage(ctx context.Context, img *vipsImage, data []byte, po *proces } iccImported := false - convertToLinear := conf.UseLinearColorspace && (scale != 1 || po.Dpr != 1) + convertToLinear := conf.UseLinearColorspace && scale != 1 if convertToLinear || !img.IsSRGB() { if err = img.ImportColourProfile(true); err != nil { @@ -536,8 +539,10 @@ func transformAnimated(ctx context.Context, img *vipsImage, data []byte, po *pro if nPages, _ := img.GetInt("n-pages"); nPages > 0 { scale := 1.0 - // Don't do scale on load if we need to crop - if po.Crop.Width == 0 && po.Crop.Height == 0 { + // Don't do scale on load if DPR != 1 or we need to crop + // because it causes problems in these cases. + // TODO: Rewrite scaling + if po.Dpr == 1.0 && po.Crop.Width == 0 && po.Crop.Height == 0 { scale = calcScale(imgWidth, frameHeight, po, imgtype) }