Documentation
¶
Overview ¶
Package stdreg registers oneimage's decoders with the standard library's image package. A blank import is all it takes:
import _ "recursiveai.org/go/oneimage/stdreg"
after which image.Decode and image.DecodeConfig read PNG, JPEG, GIF, WebP, BMP, ICO and TIFF with oneimage's own decoders, so existing code gains the formats the standard library lacks (WebP, TIFF, BMP, ICO) without change.
The standard library's contract is one picture per call, so animated files give their first frame, and pixels come as stored: the Exif orientation is not applied (use oneimage.Decode for upright pixels). The result is a concrete oneimage type that implements image.Image.
image.Decode uses the first registered decoder whose signature matches, so when image/png, image/jpeg or image/gif are imported too, the one imported (initialised) first decodes those formats. Import this package before them to prefer oneimage's decoders.
Example ¶
With the blank import, the standard library reads WebP and TIFF.
package main
import (
"bytes"
"fmt"
"image"
"recursiveai.org/go/oneimage"
)
func main() {
src := oneimage.NewPixmap(image.Rect(0, 0, 3, 2), oneimage.NRGBA8)
data, _ := oneimage.EncodeBytes(src, "tiff", nil)
img, name, err := image.Decode(bytes.NewReader(data))
fmt.Println(name, img.Bounds(), err)
}
Output: tiff (0,0)-(3,2) <nil>