mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-15 18:35:54 -07:00
Fix: Crop is doing resize. Closes #128
This commit is contained in:
parent
e099e4c9f5
commit
9b6989c3ce
2 changed files with 14 additions and 6 deletions
|
|
@ -176,7 +176,7 @@ func TestImageCropByWidth(t *testing.T) {
|
||||||
t.Errorf("Cannot process the image: %s", err)
|
t.Errorf("Cannot process the image: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = assertSize(buf, 600, 375)
|
err = assertSize(buf, 600, 1050)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
@ -190,7 +190,7 @@ func TestImageCropByHeight(t *testing.T) {
|
||||||
t.Errorf("Cannot process the image: %s", err)
|
t.Errorf("Cannot process the image: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = assertSize(buf, 480, 300)
|
err = assertSize(buf, 1680, 300)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
16
resize.go
16
resize.go
|
|
@ -401,12 +401,20 @@ func imageCalculations(o *Options, inWidth, inHeight int) float64 {
|
||||||
}
|
}
|
||||||
// Fixed width, auto height
|
// Fixed width, auto height
|
||||||
case o.Width > 0:
|
case o.Width > 0:
|
||||||
factor = xfactor
|
if o.Crop {
|
||||||
o.Height = roundFloat(float64(inHeight) / factor)
|
o.Height = inHeight
|
||||||
|
} else {
|
||||||
|
factor = xfactor
|
||||||
|
o.Height = roundFloat(float64(inHeight) / factor)
|
||||||
|
}
|
||||||
// Fixed height, auto width
|
// Fixed height, auto width
|
||||||
case o.Height > 0:
|
case o.Height > 0:
|
||||||
factor = yfactor
|
if o.Crop {
|
||||||
o.Width = roundFloat(float64(inWidth) / factor)
|
o.Width = inWidth
|
||||||
|
} else {
|
||||||
|
factor = yfactor
|
||||||
|
o.Width = roundFloat(float64(inWidth) / factor)
|
||||||
|
}
|
||||||
// Identity transform
|
// Identity transform
|
||||||
default:
|
default:
|
||||||
o.Width = inWidth
|
o.Width = inWidth
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue