项目作者: disintegration

项目描述 :
Go image decoding with respect to the EXIF orientation tag
高级语言: Go
项目地址: git://github.com/disintegration/imageorient.git
创建时间: 2017-03-31T00:03:52Z
项目社区:https://github.com/disintegration/imageorient

开源协议:MIT License

下载


imageorient

GoDoc

Package imageorient provides image decoding functions similar to standard library’s
image.Decode and image.DecodeConfig with the addition that they also handle the
EXIF orientation tag (if present).

License: MIT.

See also: http://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/

Install / Update

  1. go get -u github.com/disintegration/imageorient

Documentation

http://godoc.org/github.com/disintegration/imageorient

Usage example

  1. package main
  2. import (
  3. "image/jpeg"
  4. "log"
  5. "os"
  6. "github.com/disintegration/imageorient"
  7. )
  8. func main() {
  9. // Open the test image. This particular image have the EXIF
  10. // orientation tag set to 3 (rotated by 180 deg).
  11. f, err := os.Open("testdata/orientation_3.jpg")
  12. if err != nil {
  13. log.Fatalf("os.Open failed: %v", err)
  14. }
  15. // Decode the test image using the imageorient.Decode function
  16. // to handle the image orientation correctly.
  17. img, _, err := imageorient.Decode(f)
  18. if err != nil {
  19. log.Fatalf("imageorient.Decode failed: %v", err)
  20. }
  21. // Save the decoded image to a new file. If we used image.Decode
  22. // instead of imageorient.Decode on the previous step, the saved
  23. // image would appear rotated.
  24. f, err = os.Create("testdata/example_output.jpg")
  25. if err != nil {
  26. log.Fatalf("os.Create failed: %v", err)
  27. }
  28. err = jpeg.Encode(f, img, nil)
  29. if err != nil {
  30. log.Fatalf("jpeg.Encode failed: %v", err)
  31. }
  32. }