mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-08 23:18:19 -07:00
fix(#46): infer resize operation
This commit is contained in:
parent
4678a066b6
commit
9db6f2a0ea
3 changed files with 78 additions and 37 deletions
|
|
@ -20,6 +20,11 @@ func TestResize(t *testing.T) {
|
|||
t.Fatal("Image is not jpeg")
|
||||
}
|
||||
|
||||
size, _ := Size(newImg)
|
||||
if size.Height != options.Height || size.Width != options.Width {
|
||||
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
||||
}
|
||||
|
||||
Write("fixtures/test_out.jpg", newImg)
|
||||
}
|
||||
|
||||
|
|
@ -36,25 +41,14 @@ func TestRotate(t *testing.T) {
|
|||
t.Fatal("Image is not jpeg")
|
||||
}
|
||||
|
||||
size, _ := Size(newImg)
|
||||
if size.Height != options.Width {
|
||||
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
||||
}
|
||||
|
||||
Write("fixtures/test_rotate_out.jpg", newImg)
|
||||
}
|
||||
|
||||
func TestCorruptedImage(t *testing.T) {
|
||||
options := Options{Width: 800, Height: 600}
|
||||
buf, _ := Read("fixtures/corrupt.jpg")
|
||||
|
||||
newImg, err := Resize(buf, options)
|
||||
if err != nil {
|
||||
t.Errorf("Resize(imgData, %#v) error: %#v", options, err)
|
||||
}
|
||||
|
||||
if DetermineImageType(newImg) != JPEG {
|
||||
t.Fatal("Image is not jpeg")
|
||||
}
|
||||
|
||||
Write("fixtures/test_corrupt_out.jpg", newImg)
|
||||
}
|
||||
|
||||
func TestInvalidRotate(t *testing.T) {
|
||||
options := Options{Width: 800, Height: 600, Rotate: 111}
|
||||
buf, _ := Read("fixtures/test.jpg")
|
||||
|
|
@ -68,9 +62,35 @@ func TestInvalidRotate(t *testing.T) {
|
|||
t.Fatal("Image is not jpeg")
|
||||
}
|
||||
|
||||
size, _ := Size(newImg)
|
||||
if size.Height != options.Width {
|
||||
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
||||
}
|
||||
|
||||
Write("fixtures/test_invalid_rotate_out.jpg", newImg)
|
||||
}
|
||||
|
||||
func TestCorruptedImage(t *testing.T) {
|
||||
options := Options{Width: 800, Height: 600}
|
||||
buf, _ := Read("fixtures/corrupt.jpg")
|
||||
|
||||
newImg, err := Resize(buf, options)
|
||||
if err != nil {
|
||||
t.Errorf("Resize(imgData, %#v) error: %#v", options, err)
|
||||
}
|
||||
|
||||
if DetermineImageType(newImg) != JPEG {
|
||||
t.Fatal("Image is not jpeg")
|
||||
}
|
||||
|
||||
size, _ := Size(newImg)
|
||||
if size.Height != options.Height || size.Width != options.Width {
|
||||
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
||||
}
|
||||
|
||||
Write("fixtures/test_corrupt_out.jpg", newImg)
|
||||
}
|
||||
|
||||
func TestNoColorProfile(t *testing.T) {
|
||||
options := Options{Width: 800, Height: 600, NoProfile: true}
|
||||
buf, _ := Read("fixtures/test.jpg")
|
||||
|
|
@ -84,6 +104,11 @@ func TestNoColorProfile(t *testing.T) {
|
|||
if metadata.Profile == true {
|
||||
t.Fatal("Invalid profile data")
|
||||
}
|
||||
|
||||
size, _ := Size(newImg)
|
||||
if size.Height != options.Height || size.Width != options.Width {
|
||||
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvert(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue