-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathexample_test.go
37 lines (32 loc) · 947 Bytes
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package imageorient_test
import (
"image/jpeg"
"log"
"os"
"github.com/disintegration/imageorient"
)
func ExampleDecode() {
// Open the test image. This particular image has the EXIF
// orientation tag set to 3 (rotated by 180 deg).
f, err := os.Open("testdata/orientation_3.jpg")
if err != nil {
log.Fatalf("os.Open failed: %v", err)
}
// Decode the test image using the imageorient.Decode function
// to handle the image orientation correctly.
img, _, err := imageorient.Decode(f)
if err != nil {
log.Fatalf("imageorient.Decode failed: %v", err)
}
// Save the decoded image to a new file. If we used image.Decode
// instead of imageorient.Decode on the previous step, the saved
// image would appear rotated.
f, err = os.Create("testdata/example_output.jpg")
if err != nil {
log.Fatalf("os.Create failed: %v", err)
}
err = jpeg.Encode(f, img, nil)
if err != nil {
log.Fatalf("jpeg.Encode failed: %v", err)
}
}