prism

package module
v0.0.0-...-0689314 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2018 License: MIT Imports: 15 Imported by: 0

README

Prism

Build Status

Fast Go image encoding, decoding, and transformations using OpenCV, libpng, and libjpeg-turbo.

Dependencies (dynamically linked)

  • opencv 2.4.x
  • libturbo-jpeg 1.4+

Example

import(
  "os"

  "github.com/cotap/prism"
)

func main() {
  f, _ := os.Open("example.jpg")

  img, _ := prism.Decode(f)
  defer img.Release() // ensures timely release of C heap memory

  _ = img.FlipV()
  _ = img.Fit(500, 500)

  w, _ := os.Create("resized.jpg")
  defer w.Close()

  // fast encoding with libjpeg-turbo
  prism.EncodeJPEG(w, img, 90)

  // or, since prism.Image implements image.Image:
  //   jpeg.Encode(w, img, &jpeg.Options{Quality: 90})
}

Memory Management

Prism allocates memory for image decoding and processing using the OpenCV allocator on the C heap. In order to avoid long-term leaks, prism uses Go's runtime.SetFinalizer to release C memory when the Go object is GC'd.

HOWEVER, because Go's collector can't see into the C heap, it may not run as frequently as needed to keep memory usage low. In order to ensure most efficient memory usage, always call func (img *prism.Image) Release() after you're done with an image.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PixelLimit = 75000000 // 75MP

Functions

func EncodeJPEG

func EncodeJPEG(w io.Writer, img *Image, quality int) (err error)

EncodeJPEG writes the Image img to w in JPEG 4:2:0 baseline format with the given quality, from 1 - 100.

func EncodePNG

func EncodePNG(w io.Writer, img *Image, compression int) (err error)

EncodePNG writes the Image img to w in PNG format with the given Zlib compression level, from 0 (none) - 9

func Validate

func Validate(r io.Reader) (err error)

Types

type Image

type Image struct {
	// contains filtered or unexported fields
}

func Decode

func Decode(r io.Reader) (img *Image, err error)

func (*Image) At

func (img *Image) At(x, y int) color.Color

func (*Image) Bounds

func (img *Image) Bounds() image.Rectangle

func (*Image) Bytes

func (img *Image) Bytes() []byte

func (*Image) ColorModel

func (img *Image) ColorModel() color.Model

func (*Image) Copy

func (img *Image) Copy() *Image

func (*Image) Fit

func (img *Image) Fit(width, height int) (err error)

func (*Image) FlipH

func (img *Image) FlipH() error

func (*Image) FlipV

func (img *Image) FlipV() error

func (*Image) Release

func (img *Image) Release()

func (*Image) Reorient

func (img *Image) Reorient() (err error)

func (*Image) Resize

func (img *Image) Resize(width, height int) (err error)

func (*Image) Rotate180

func (img *Image) Rotate180() error

func (*Image) Rotate270

func (img *Image) Rotate270() (err error)

func (*Image) Rotate90

func (img *Image) Rotate90() (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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