orientation

package module
v0.0.0-...-8445e82 Latest Latest
Warning

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

Go to latest
Published: May 2, 2017 License: MIT Imports: 5 Imported by: 2

README

orientation Codeship Status for minodisk/orientation Go Report Card codecov GoDoc MIT License

Apply EXIF Orientation tag to the pixels of a image.

Installation

go get github.com/minodisk/orientation

Usage

import (
	_ "image/gif"
	_ "image/jpeg"
	_ "image/png"

	"github.com/minodisk/orientation"
)

func main() {
	file, _ := os.Open("path/to/image")
	img, err := orientation.Apply(file)
	if err != nil {
		if err, ok := err.(*orientation.DecodeError); ok {
			panic(err)
		}
	}
	fmt.Println(visualize(img))
}
When processing any JPEG:
import (
	_ "image/jpeg"

	"github.com/minodisk/orientation"
)

func main() {
	file, _ := os.Open("path/to/jpeg")
	img, err := orientation.Apply(file)
	if err != nil {
		if err, ok := err.(*orientation.DecodeError); ok {
			panic(err)
		}
	}
	fmt.Println(visualize(img))
}
When processing only JPEG with correct Orientation tag:
import (
	_ "image/jpeg"

	"github.com/minodisk/orientation"
)

func main() {
	file, _ := os.Open("path/to/jpeg")
	img, err := orientation.Apply(file)
	if err != nil {
		panic(err)
	}
	fmt.Println(visualize(img))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(r io.Reader) (image.Image, error)

Apply reflects the image's EXIF orientation tag on the image pixels. If the image can not be decoded, it returns nil and an error. If an error occurs during subsequent processing, it returns the decoded image and an error.

func Decode

func Decode(r io.Reader) (image.Image, error)

Decode decodes and returns the image. If decoding fails, it returns nil and DecodeError. If the format is not JPEG, it returns the decoded image and FormatError.

func Orient

func Orient(img image.Image, tag int) (image.Image, error)

Orient reflects the rotation indicated by the tag in the img. If the specified orientation tag is unknown, returns OrientError.

func Orient1

func Orient1(s image.Image) image.Image

Orient1 returns s. Process like this:

111    111
100    100
110 -> 110
100    100
100    100

func Orient2

func Orient2(s image.Image) image.Image

Orient2 returns a new image in which the right side replaced by the left side. Process like this:

111    111
001    100
011 -> 110
001    100
001    100

func Orient3

func Orient3(s image.Image) image.Image

Orient3 returns a new image in which the bottom side is replaced by the upper side and the right side replaced by the left side. Process like this:

001    111
001    100
011 -> 110
001    100
111    100

func Orient4

func Orient4(s image.Image) image.Image

Orient4 returns a new image in which the bottom side is replaced by the upper side. Process like this:

100    111
100    100
110 -> 110
100    100
111    100

func Orient5

func Orient5(s image.Image) image.Image

Orient5 returns a new image in which the left side is replaced by the upper side and the upper side is replaced by the left side. Process like this:

         111
11111    100
10100 -> 110
10000    100
         100

func Orient6

func Orient6(s image.Image) image.Image

Orient6 returns a new image in which the left side is replaced by the upper side and the bottom side is replaced by the left side. Process like this:

         111
10000    100
10100 -> 110
11111    100
         100

func Orient7

func Orient7(s image.Image) image.Image

Orient7 returns a new image in which the right side is replaced by the upper side and the bottom side is replaced by the left side. Process like this:

         111
00001    100
00101 -> 110
11111    100
         100

func Orient8

func Orient8(s image.Image) image.Image

Orient8 returns a new image in which the right side is replaced by the upper side and the upper side is replaced by the left side. Process like this:

         111
11111    100
00101 -> 110
00001    100
         100

func SwapSides

func SwapSides(r image.Rectangle) image.Rectangle

SwapSides returns a new rectangle that swaps the width and height of the rectangle.

func Tag

func Tag(r io.Reader) (int, error)

Tag decodes the orientation tag from the image EXIF and returns it. If the EXIF can not be decoded, the orientation tag does not exist, or the orientation tag is not int, it returns TagError.

Types

type DecodeError

type DecodeError struct {
	Raw error
}

DecodeError is returned by Apply and Decode when image.Decode returns an error.

func (*DecodeError) Cause

func (e *DecodeError) Cause() error

Cause returns the underlying cause of DecodeError.

func (*DecodeError) Error

func (e *DecodeError) Error() string

type FormatError

type FormatError struct {
	Raw error
}

FormatError is returned by Apply and Decode when the format of decoded image is not jpeg.

func (*FormatError) Cause

func (e *FormatError) Cause() error

Cause returns the underlying cause of FormatError.

func (*FormatError) Error

func (e *FormatError) Error() string

type OrientError

type OrientError struct {
	Raw error
}

OrientError is returned by Apply and Tag when the specified orientation tag is unknown.

func (*OrientError) Cause

func (e *OrientError) Cause() error

Cause returns the underlying cause of OrientError.

func (*OrientError) Error

func (e *OrientError) Error() string

type TagError

type TagError struct {
	Raw error
}

TagError is returned by Apply and Tag when the EXIF can not be decoded, the orientation tag does not exits, or the orientation tag is not int.

func (*TagError) Cause

func (e *TagError) Cause() error

Cause returns the underlying cause of TagError.

func (*TagError) Error

func (e *TagError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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