Skip to content

Commit

Permalink
Merge pull request #183 from greut/autorotate
Browse files Browse the repository at this point in the history
Test cases for the EXIF autorotate
  • Loading branch information
h2non authored Sep 6, 2017
2 parents 833af3b + b752fe8 commit d30fc3f
Show file tree
Hide file tree
Showing 34 changed files with 62 additions and 2 deletions.
Binary file added fixtures/exif/Landscape_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Landscape_1_out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Landscape_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Landscape_2_out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Landscape_3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Landscape_3_out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Landscape_4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Landscape_4_out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Landscape_5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Landscape_5_out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Landscape_6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Landscape_6_out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Landscape_7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Landscape_7_out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Landscape_8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Landscape_8_out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Portrait_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Portrait_1_out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Portrait_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Portrait_2_out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Portrait_3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Portrait_3_out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Portrait_4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Portrait_4_out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Portrait_5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fixtures/exif/Portrait_5_out.jpg
Binary file added fixtures/exif/Portrait_6.jpg
Binary file added fixtures/exif/Portrait_6_out.jpg
Binary file added fixtures/exif/Portrait_7.jpg
Binary file added fixtures/exif/Portrait_7_out.jpg
Binary file added fixtures/exif/Portrait_8.jpg
Binary file added fixtures/exif/Portrait_8_out.jpg
4 changes: 2 additions & 2 deletions resize.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,15 +518,15 @@ func calculateRotationAndFlip(image *C.VipsImage, angle Angle) (Angle, bool) {
break // flip 1
case 7:
flip = true
rotate = D90
rotate = D270
break // flip 6
case 4:
flip = true
rotate = D180
break // flip 3
case 5:
flip = true
rotate = D270
rotate = D90
break // flip 8
}

Expand Down
60 changes: 60 additions & 0 deletions resize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bimg
import (
"bytes"
"crypto/md5"
"fmt"
"image"
"image/jpeg"
"io/ioutil"
Expand Down Expand Up @@ -393,6 +394,65 @@ func TestResizePngWithTransparency(t *testing.T) {
Write("fixtures/transparent_out.png", newImg)
}

func TestRotationAndFlip(t *testing.T) {
files := []struct {
Name string
Angle Angle
Flip bool
}{
{"Landscape_1", 0, false},
{"Landscape_2", 0, true},
{"Landscape_3", D180, false},
{"Landscape_4", D180, true},
{"Landscape_5", D90, true},
{"Landscape_6", D90, false},
{"Landscape_7", D270, true},
{"Landscape_8", D270, false},
{"Portrait_1", 0, false},
{"Portrait_2", 0, true},
{"Portrait_3", D180, false},
{"Portrait_4", D180, true},
{"Portrait_5", D90, true},
{"Portrait_6", D90, false},
{"Portrait_7", D270, true},
{"Portrait_8", D270, false},
}

for _, file := range files {
img, err := os.Open(fmt.Sprintf("fixtures/exif/%s.jpg", file.Name))
if err != nil {
t.Fatal(err)
}

buf, err := ioutil.ReadAll(img)
if err != nil {
t.Fatal(err)
}
img.Close()

image, _, err := loadImage(buf)
if err != nil {
t.Fatal(err)
}

angle, flip := calculateRotationAndFlip(image, D0)
if angle != file.Angle {
t.Errorf("Rotation for %v expected to be %v. got %v", file.Name, file.Angle, angle)
}
if flip != file.Flip {
t.Errorf("Flip for %v expected to be %v. got %v", file.Name, file.Flip, flip)
}

// Visual debugging.
newImg, err := Resize(buf, Options{})
if err != nil {
t.Fatal(err)
}

Write(fmt.Sprintf("fixtures/exif/%s_out.jpg", file.Name), newImg)
}
}

func TestIfBothSmartCropOptionsAreIdentical(t *testing.T) {
if !(VipsMajorVersion >= 8 && VipsMinorVersion > 4) {
t.Skipf("Skipping this test, libvips doesn't meet version requirement %s > 8.4", VipsVersion)
Expand Down

0 comments on commit d30fc3f

Please sign in to comment.