Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,29 @@ func TestImageExtractZero(t *testing.T) {
}

func TestImageEnlarge(t *testing.T) {
buf, err := initImage("test.png").Enlarge(500, 375)
if err != nil {
t.Errorf("Cannot process the image: %#v", err)
// test.png is 400x300
tests := []struct {
input []int
expected []int
}{
{[]int{500, 375}, []int{500, 375}},
{[]int{577, 1250}, []int{577, 433}},
{[]int{412, 3460}, []int{412, 309}},
}

err = assertSize(buf, 500, 375)
if err != nil {
t.Error(err)
}
for c, test := range tests {
buf, err := initImage("test.png").Enlarge(test.input[0], test.input[1])
if err != nil {
t.Errorf("Cannot process the image: %#v", err)
}

Write("testdata/test_enlarge_out.jpg", buf)
err = assertSize(buf, test.expected[0], test.expected[1])
if err != nil {
t.Error(err)
}

Write(fmt.Sprintf("testdata/test_enlarge_out_%d.jpg", c), buf)
}
}

func TestImageEnlargeAndCrop(t *testing.T) {
Expand Down
10 changes: 9 additions & 1 deletion resizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,15 @@ func imageCalculations(o *Options, inWidth, inHeight int) float64 {
switch {
// Fixed width and height
case o.Width > 0 && o.Height > 0:
factor = math.Min(xfactor, yfactor)
// Use minimum factor for croping or downscaling
// use maximum factor for upscaling
// Maybe this should be:
// if o.Crop || (o.Width <= inWidth || o.Height <= inHeight) {
if o.Crop || (o.Width < inWidth || o.Height < inHeight) {
factor = math.Min(xfactor, yfactor)
} else {
factor = math.Max(xfactor, yfactor)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi. this is a revert from #198 with an additional check. Might be better, indeed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the hint. Wat was the reason for removing the check in first place?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests were breaking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, TestResizeVerticalImage fails with #198.
We see some shrinking issues introduced with #198, currently still under investigation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@greut please see #205

// Fixed width, auto height
case o.Width > 0:
if o.Crop {
Expand Down