Documentation
¶
Overview ¶
Package rasterfit reduces a raster image to fit a box, decoding it in the platform under a bound on the memory its pixels take (#2697). A browser decodes an image at its natural size, so its memory grows with the image's pixels rather than with the size it is shown at; the thumbnail renderer was taken past its memory limit by one photograph a mail attachment carried. The tile worker hands the renderer the reduced copy instead.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnreadable = errors.New("rasterfit: the image could not be decoded")
ErrUnreadable is an image whose header or pixels no decoder here reads. A browser may still read it (an animated WebP), so a caller can hand it on as stored.
Functions ¶
func BytesPerPixel ¶
BytesPerPixel is what decoding an image of model holds per pixel. A JPEG's YCbCr counts 4: a progressive JPEG keeps its coefficients beside the image while it decodes.
func Fit ¶
func Fit(ctx context.Context, data []byte, width, height int, maxBytes int64) (out []byte, reduced bool, err error)
Fit returns data as a PNG reduced to fit width x height, proportions and transparency kept, and reduced true. An image already within the box is returned unchanged with reduced false. An image whose decoded pixels would take more than maxBytes is a *TooLargeError, read from its header alone; one that cannot be decoded is ErrUnreadable. A context ended while waiting for the decode slot returns its error.
Types ¶
type TooLargeError ¶
TooLargeError is an image whose header declares more decoded pixels than the bound allows.
func (*TooLargeError) Error ¶
func (e *TooLargeError) Error() string