README.md

 1# imageorient
 2
 3[![GoDoc](https://godoc.org/github.com/disintegration/imageorient?status.svg)](https://godoc.org/github.com/disintegration/imageorient)
 4
 5Package `imageorient` provides image decoding functions similar to standard library's
 6`image.Decode` and `image.DecodeConfig` with the addition that they also handle the
 7EXIF orientation tag (if present).
 8
 9License: MIT.
10
11See also: http://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/
12
13## Install / Update
14
15    go get -u github.com/disintegration/imageorient
16
17## Documentation
18
19http://godoc.org/github.com/disintegration/imageorient
20
21## Usage example
22
23```go
24package main
25
26import (
27	"image/jpeg"
28	"log"
29	"os"
30
31	"github.com/disintegration/imageorient"
32)
33
34func main() {
35	// Open the test image. This particular image have the EXIF
36	// orientation tag set to 3 (rotated by 180 deg).
37	f, err := os.Open("testdata/orientation_3.jpg")
38	if err != nil {
39		log.Fatalf("os.Open failed: %v", err)
40	}
41
42	// Decode the test image using the imageorient.Decode function
43	// to handle the image orientation correctly.
44	img, _, err := imageorient.Decode(f)
45	if err != nil {
46		log.Fatalf("imageorient.Decode failed: %v", err)
47	}
48
49	// Save the decoded image to a new file. If we used image.Decode
50	// instead of imageorient.Decode on the previous step, the saved
51	// image would appear rotated.
52	f, err = os.Create("testdata/example_output.jpg")
53	if err != nil {
54		log.Fatalf("os.Create failed: %v", err)
55	}
56	err = jpeg.Encode(f, img, nil)
57	if err != nil {
58		log.Fatalf("jpeg.Encode failed: %v", err)
59	}
60}
61```