aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2026-06-11 23:31:49 -0700
committerRose Hogenson <rosehogenson@posteo.net>2026-06-11 23:31:49 -0700
commit6dba3cc038d8adfc35d893a4ed94aa001fe9c0b0 (patch)
tree197601b82d3887f923fd6c22df424ca779ba9581
parent38b5c1a8ab5a6e9c1eadc4ebb56b4af9dc0cb7c6 (diff)
downloadimgutil-6dba3cc038d8adfc35d893a4ed94aa001fe9c0b0.tar.zst
Fix a bug where image is stretched with -m block
-rw-r--r--icat.go15
1 files changed, 8 insertions, 7 deletions
diff --git a/icat.go b/icat.go
index d1f7388..2b69170 100644
--- a/icat.go
+++ b/icat.go
@@ -234,14 +234,15 @@ func medianCut(img image.Image) color.Palette {
func printImg(img image.Image, maxX, maxY, pixelX, pixelY int) error {
x := min(img.Bounds().Dx(), maxX)
y := min(img.Bounds().Dy(), maxY)
- if x != img.Bounds().Dx() || y != img.Bounds().Dy() {
- // Try not to stretch the image.
- if y == 0 || x != 0 && img.Bounds().Dy()*x <= img.Bounds().Dx()*y*pixelY/pixelX {
- y = divRound(img.Bounds().Dy()*x*pixelX, img.Bounds().Dx()*pixelY)
- } else {
- x = divRound(img.Bounds().Dx()*y*pixelY, pixelX*img.Bounds().Dy())
- }
+ // Try not to stretch the image.
+ if y == 0 || x != 0 && img.Bounds().Dy()*x*pixelX <= img.Bounds().Dx()*y*pixelY {
+ y = divRound(img.Bounds().Dy()*x*pixelX, img.Bounds().Dx()*pixelY)
+ } else {
+ x = divRound(img.Bounds().Dx()*y*pixelY, pixelX*img.Bounds().Dy())
+ }
+
+ if x != img.Bounds().Dx() || y != img.Bounds().Dy() {
dst := image.NewRGBA(image.Rect(0, 0, x, y))
draw.BiLinear.Scale(dst, dst.Bounds(), img, img.Bounds(), draw.Src, nil)
img = dst