Home Download Docs Code Community
import "perkeep.org/pkg/images/fastjpeg"
Overview
Index

Overview ▾

Package fastjpeg uses djpeg(1), from the Independent JPEG Group's (www.ijg.org) jpeg package, to quickly down-sample images on load. It can sample images by a factor of 1, 2, 4 or 8. This reduces the amount of data that must be decompressed into memory when the full resolution image isn't required, i.e. in the case of generating thumbnails.

Index

Variables
func Available() bool
func DecodeDownsample(r io.Reader, factor int) (image.Image, error)
func Factor(w, h, sw, sh int) int
type DjpegFailedError
    func (dfe DjpegFailedError) Error() string

Package files

fastjpeg.go

Variables

var (
    ErrDjpegNotFound = errors.New("fastjpeg: djpeg not found in path")
)

func Available

func Available() bool

func DecodeDownsample

func DecodeDownsample(r io.Reader, factor int) (image.Image, error)

DecodeDownsample decodes JPEG data in r, down-sampling it by factor. If djpeg is not found, err is ErrDjpegNotFound and r is not read from. If the execution of djpeg, or decoding the resulting PNM fails, error will be of type DjpegFailedError.

func Factor

func Factor(w, h, sw, sh int) int

Factor returns the sample factor DecodeSample should use to generate a sampled image greater than or equal to sw x sh pixels given a source image of w x h pixels.

type DjpegFailedError

type DjpegFailedError struct {
    Err error
}

DjpegFailedError wraps errors returned when calling djpeg and handling its response. Used for type asserting and retrying with other jpeg decoders, i.e. the standard library's jpeg.Decode.

func (DjpegFailedError) Error

func (dfe DjpegFailedError) Error() string
Website layout inspired by git and memcached,
design done by up all day creative solutions.
Content by the authors.