orientation

package module
v0.0.0-...-30cdc5a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2020 License: MIT Imports: 6 Imported by: 2

README

exif-orientation

example

package main

import (
	"bytes"
	orientation "github.com/takumakei/exif-orientation"
	"image"
	"image/jpeg"
	"io/ioutil"
	"log"
	"os"
)

func main() {
	b, err := ioutil.ReadFile("./examples/Landscape_7.jpg")
	if err != nil {
		log.Fatal(err)
	}

	r := bytes.NewReader(b)

	img, _, err := image.Decode(r)
	if err != nil {
		log.Fatal(err)
	}

	r.Reset(b)
	o, _ := orientation.Read(r)
	img = orientation.Normalize(img, o)

	f, err := os.Create("normalized.jpg")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	if err := jpeg.Encode(f, img, &jpeg.Options{Quality: jpeg.DefaultQuality}); err != nil {
		log.Fatal(err)
	}
}

Documentation

Overview

Package orientation provides functions to use orientation of EXIF.

Example
package main

import (
	"bytes"
	"image"
	"image/jpeg"
	"io/ioutil"
	"log"
	"os"

	orientation "github.com/takumakei/exif-orientation"
)

func main() {
	b, err := ioutil.ReadFile("./examples/Landscape_7.jpg")
	if err != nil {
		log.Fatal(err)
	}

	r := bytes.NewReader(b)

	img, _, err := image.Decode(r)
	if err != nil {
		log.Fatal(err)
	}

	r.Reset(b)
	o, _ := orientation.Read(r)
	img = orientation.Normalize(img, o)

	f, err := os.Create("normalized.jpg")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	if err := jpeg.Encode(f, img, &jpeg.Options{Quality: jpeg.DefaultQuality}); err != nil {
		log.Fatal(err)
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRGBA

func NewRGBA(bounds image.Rectangle) draw.Image

NewRGBA returns image.NewRGBA(bounds).

Normalize uses NewRGBA.

func Normalize

func Normalize(src image.Image, orientation Orientation) image.Image

Normalize returns an image that of orientation is TopLeft. In case of orientation is TopLeft, Normalize returns src itself. Otherwise the image returned would be created by NewRGBA.

func NormalizeCopy

func NormalizeCopy(src image.Image, orientation Orientation, creator func(image.Rectangle) draw.Image) draw.Image

NormalizeCopy returns new copied image that of orientation is TopLeft.

The image returned would be created by creator.

Types

type Orientation

type Orientation int

Orientation

       1:TopLeft                   2:TopRight
        FFFFFFFF                    FFFFFFFF
        FF                                FF
        FFFFFF                        FFFFFF
        FF                                FF
        FF                                FF
        FF                                FF

            8:LeftBottom    5:LeftTop
FF          FFFFFFFFFFFF    FFFFFFFFFFFF          FF
FF  FF            FF  FF    FF  FF            FF  FF
FF  FF            FF  FF    FF  FF            FF  FF
FFFFFFFFFFFF          FF    FF          FFFFFFFFFFFF
6:RightTop                             7:RightBottom

              FF                    FF
              FF                    FF
              FF                    FF
          FFFFFF                    FFFFFF
              FF                    FF
        FFFFFFFF                    FFFFFFFF
      3:BottomRight               4:BottomLeft
const (
	TopLeft Orientation = 1 + iota
	TopRight
	BottomRight
	BottomLeft
	LeftTop
	RightTop
	RightBottom
	LeftBottom
)

func Read

func Read(r io.Reader) (Orientation, error)

Read returns an orientation, TopLeft in case of err != nil.

func (Orientation) String

func (i Orientation) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL