Documentation
¶
Overview ¶
Package images is a pure-Go (no cgo) image library that backs the Ruby `images` gem for the go-embedded-ruby interpreter (rbgo). It unifies three capability sets behind one clean, Ruby-bindable Go API:
- Processing (MiniMagick / ruby-vips replacement): the Image type decodes PNG, JPEG, GIF, BMP, TIFF and WebP, reports dimensions/format/metadata, and offers resize, thumbnail, crop, rotate, flip, flop, grayscale, format conversion, and blob/file output — with no ImageMagick or libvips.
- A chunky_png-style canvas lives in the sub-package github.com/go-ruby-images/images/canvas, with per-pixel access, primitive drawing, alpha composition and PNG I/O.
- scikit-image / go-images operations are exposed as methods on Image (blur, sharpen, edges, threshold, morphology, colour ops), reusing the github.com/go-images/images engine rather than reimplementing it.
Every operation is deterministic (fixed algorithms, no randomness) so the results are reproducible across the six supported 64-bit architectures and the js/wasm and wasip1/wasm targets.
Index ¶
- func Encodable() []string
- func Supported() []string
- type Image
- func (im *Image) At(x, y int) (color.RGBA, error)
- func (im *Image) Blur(radius int) (*Image, error)
- func (im *Image) Brightness(delta float64) *Image
- func (im *Image) Canny(sigma, low, high float64) (*Image, error)
- func (im *Image) Clone() *Image
- func (im *Image) Close(radius int) (*Image, error)
- func (im *Image) Contrast(factor float64) *Image
- func (im *Image) Convert(format string) (*Image, error)
- func (im *Image) Convolve(width, height int, weights []float64) (*Image, error)
- func (im *Image) Crop(x, y, width, height int) (*Image, error)
- func (im *Image) Dilate(radius int) (*Image, error)
- func (im *Image) Dimensions() (int, int)
- func (im *Image) Encode(w io.Writer) error
- func (im *Image) Erode(radius int) (*Image, error)
- func (im *Image) Flip() *Image
- func (im *Image) Flop() *Image
- func (im *Image) Format() string
- func (im *Image) GaussianBlur(sigma float64) (*Image, error)
- func (im *Image) Grayscale() *Image
- func (im *Image) Height() int
- func (im *Image) Invert() *Image
- func (im *Image) Laplacian() *Image
- func (im *Image) Median(radius int) (*Image, error)
- func (im *Image) Metadata() Metadata
- func (im *Image) Open(radius int) (*Image, error)
- func (im *Image) Otsu() *Image
- func (im *Image) OtsuThreshold() uint8
- func (im *Image) Prewitt() *Image
- func (im *Image) RGBA() *image.RGBA
- func (im *Image) Resize(width, height int) (*Image, error)
- func (im *Image) ResizeNearest(width, height int) (*Image, error)
- func (im *Image) Rotate(degrees int) (*Image, error)
- func (im *Image) Scharr() *Image
- func (im *Image) Sharpen() *Image
- func (im *Image) Sobel() *Image
- func (im *Image) Threshold(t uint8) *Image
- func (im *Image) Thumbnail(maxWidth, maxHeight int) (*Image, error)
- func (im *Image) ToBlob() ([]byte, error)
- func (im *Image) UnsharpMask(radius, amount float64) (*Image, error)
- func (im *Image) Width() int
- func (im *Image) Write(path string) error
- type Metadata
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
Image is the processing handle at the heart of the library — the pure-Go analogue of a MiniMagick::Image or a Vips::Image. It wraps an *image.RGBA together with the format it was decoded from (or last converted to). All transforming methods return a new Image and never mutate the receiver, so a handle can be shared safely.
func FromImage ¶
FromImage wraps an existing image.Image, converting it to RGBA. The reported format defaults to PNG. It bridges the standard-library image world into the Image API.
func New ¶
New returns a fresh Image of the given size filled with fill. The default output format is PNG. It is the entry point for building an image from scratch, mirroring Vips::Image.black plus a fill.
func Read ¶
Read decodes an image from an in-memory byte slice, the equivalent of MiniMagick::Image.read(blob).
func (*Image) At ¶
At returns the colour at (x, y). It reports an error when the coordinates fall outside the image bounds.
func (*Image) Brightness ¶
Brightness returns the image with delta added to every channel (clamped).
func (*Image) Canny ¶
Canny returns the Canny edge map for the given Gaussian sigma and the low and high hysteresis thresholds. It errors on a non-positive sigma.
func (*Image) Convert ¶
Convert changes the output format used by Encode, ToBlob and Write (when the path carries no extension). It returns an error for formats this package cannot encode.
func (*Image) Convolve ¶
Convolve returns the image convolved with an arbitrary odd-sized kernel of width x height weights (row-major). It errors on non-positive, even, or mismatched dimensions.
func (*Image) Crop ¶
Crop returns the rectangular region of size width x height anchored at (x, y). The region must lie fully within the image.
func (*Image) Dilate ¶
Dilate returns the grayscale morphological dilation (radius must be positive).
func (*Image) Dimensions ¶
Dimensions returns the width and height in pixels.
func (*Image) Erode ¶
Erode returns the grayscale morphological erosion over a square structuring element of the given radius (radius must be positive).
func (*Image) GaussianBlur ¶
GaussianBlur returns a Gaussian blur with the given sigma (sigma must be positive).
func (*Image) Grayscale ¶
Grayscale returns the image converted to grayscale (Rec. 601 luminance replicated across the R, G and B channels).
func (*Image) Median ¶
Median returns a median-filtered image over a square window of the given radius (radius must be positive).
func (*Image) OtsuThreshold ¶
OtsuThreshold returns the automatically chosen Otsu threshold value.
func (*Image) RGBA ¶
RGBA returns the underlying *image.RGBA. Callers that mutate it affect this Image; use Clone first to keep the original intact.
func (*Image) Resize ¶
Resize returns the image scaled to width x height using bilinear interpolation. Both dimensions must be positive.
func (*Image) ResizeNearest ¶
ResizeNearest returns the image scaled to width x height using nearest-neighbour sampling, which preserves hard pixel edges.
func (*Image) Rotate ¶
Rotate returns the image rotated clockwise by degrees, which must be a multiple of 90 (0, 90, 180 or 270 after normalisation).
func (*Image) Threshold ¶
Threshold returns a binary image: pixels whose luminance is at least t become white, the rest black.
func (*Image) Thumbnail ¶
Thumbnail scales the image to fit inside a maxWidth x maxHeight box while preserving the aspect ratio, the equivalent of MiniMagick's `resize "WxH"`. The result is never enlarged beyond the original dimensions and each side is at least one pixel. Both bounds must be positive.
func (*Image) ToBlob ¶
ToBlob encodes the image in its current format and returns the bytes, the equivalent of MiniMagick::Image#to_blob.
func (*Image) UnsharpMask ¶
UnsharpMask returns an unsharp-masked image (radius must be positive).
